简体   繁体   English

PHP:ssh2_connect:无法远程连接到本地主机或计算机

[英]PHP: ssh2_connect: cant connect to localhost or machine remotely

For the sake of my explanation, keep the following im mind. 为了我的解释,请注意以下几点。

Machine 1 Internal = 127.0.0.1
Machine 1 External = 192.0.0.1

Machine 2 Internal = 127.0.0.2
Machime 2 External = 192.0.0.2

Client External = 10.0.0.1


So, I will try to connect to the internal IP of Machine #1, while on Machine #1: 因此,在机器#1上,我将尝试连接到机器#1的内部IP:

$server = "127.0.0.1";
$conn = ssh2_connect($server, 22);


Results in [/var/log/httpd/error_log]: [/ var / log / httpd / error_log]中的结果:

[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 127.0.0.1 on port 22 in /var/www/html/file.php on line 8
[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 127.0.0.1 in /var/www/html/file.php on line 8

Changing the IP from internal to external yielded the same error. 将IP从内部更改为外部会产生相同的错误。

Now, I will try to connect to the external IP of machine #1 while the PHP file is ran off of Machine #2's webserver: 现在,当PHP文件从2号机的Web服务器上运行时,我将尝试连接至1号机的外部IP:

$server = "192.0.0.1"
$conn = ssh2_connect($server);

Results in [/var/log/httpd/error_log]: [/ var / log / httpd / error_log]中的结果:

[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 192.0.0.1 on port 22 in /var/www/html/file.php on line 8
[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 192.0.0.1 in /var/www/html/file.php on line 8

All of this is the case, but oddly enough, if I run the exact code through the php -a interpreter, and proceed to authenticate and run a command, all works flawlessly. 所有这些都是如此,但是奇怪的是,如果我通过php -a解释器运行确切的代码,并继续进行身份验证和运行命令,那么所有这些都可以正常工作。

What is the issue?? 有什么问题??

I was able to resolve this by using setenforce 0 . 我可以通过使用setenforce 0来解决此问题。 Honestly the most puzzling issue I've had while programming. 老实说,我在编程时遇到的最令人困惑的问题。 Thanks for the help! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM