PHP远程控制cmd,通过PHP在远程机器上执行命令

这篇博客介绍了如何通过PHP在Linux上运行SSH命令,连接到远程服务器B执行特定命令,如`uptime`。文章提到了使用`exec()`函数,并给出了一个包含自动认证帮助链接的非工作代码示例。建议的流程是在服务器A上建立从PHP到服务器B的SSH连接,以执行远程操作。
摘要由CSDN通过智能技术生成

通过服务器A上的

PHP运行SSH命令到服务器B.

要使用PHP在Linux上运行命令,请使用exec()命令.

我希望这会让你开始寻找正确的方向.

查看这两个帖子以自动化密码提示

这是一个使用非工作代码的快速示例,可以让您思考:

$server = "serverB.example.org";

//ip address will work too i.e. 192.168.254.254 just make sure this is your public ip address not private as is the example

//specify your username

$username = "root";

//select port to use for SSH

$port = "22";

//command that will be run on server B

$command = "uptime";

//form full command with ssh and command, you will need to use links above for auto authentication help

$cmd_string = "ssh -p ".$port." ".$username."@".$server." ".$command;

//this will run the above command on server A (localhost of the php file)

exec($cmd_string, $output);

//return the output to the browser

//This will output the uptime for server B on page on server A

echo '

';

print_r($output);

echo '

';

?>

建议的流程是在服务器A上运行命令到SSH到服务器B.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值