如何远程重启ubuntu 16.04? [英] How do I reboot ubuntu 16.04 remotely?

查看:274
本文介绍了如何远程重启ubuntu 16.04?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试通过PHP重新启动我的Ubuntu 16.04。

我安装了SSH2扩展,编写代码并且有问题:

Hi,
I try to reboot my Ubuntu 16.04 through PHP.
I installed SSH2 extension, write code and it have a problem:

SSH connection: [OK]
Athentication: [OK]
Shell: [OK]
reboot -i
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-66-generic x86_64)

* Documentation: https://help.ubuntu.com/

332 packages can be updated.
4 updates are security updates.

Last login: Sun Mar 12 18:50:57 2017 from 192.168.80.137
]0;lam@lam: ~lam@lam:~$ reboot 
Failed to set wall message, ignoring: Interactive authentication required.
Failed to reboot system via logind: Interactive authentication required.
Failed to start reboot.target: Interactive authentication required.
See system logs and 'systemctl status reboot.target' for details.
Failed to open /dev/initctl: Permission denied
Failed to talk to init daemon. 



然后我使用命令行:


Then I use command line:

#chmod 777 /dev/initctl



这是工作,Ubuntu通过PHP重新启动!!!!。

但重新启动后,我尝试获取的PHP代码,我在上面显示类似的错误。我必须再次#chmod 777 / dev / initctl来保持它的工作。

请帮助我。

P / s:这里我的PHP代码


It's work, Ubuntu reboot through PHP!!!!.
But after reboot, I try php code I gain, I show similar error above. I must #chmod 777 /dev/initctl again to keep it's work.
Please help me.
P/s: here my php code

<?php
        echo "SSH connection: ";
        if (!($resource=@ssh2_connect("192.168.80.137"))) {
                echo "[FAILED]<br />";
                exit(1);
        }
        echo "[OK]<br />";

        echo "Athentication: ";
        if (!@ssh2_auth_password($resource,"lam","root")) {
                echo "[FAILED]<br />";
                exit(1);
        }
        echo "[OK]<br />";

        echo "Shell: ";
        if (!($stdio = @ssh2_shell($resource,"xterm"))) {
                echo "[FAILED]<br />";
                exit(1);
        }
        echo "[OK]<br />";
		//$permission = "chmod 777 /dev/initctl \n";
		//fwrite($stdio,$permission);
        $command = "reboot\n";
        fwrite($stdio,$command);

        sleep(1);

        while($line = fgets($stdio)) {
                flush();
                echo $line."<br />";
        }

        fclose($stdio);
?>





我有什么试过:



通过PHP重启我的Ubuntu 16.04。



What I have tried:

Reboot my Ubuntu 16.04 through PHP.

推荐答案

reboot
无法设置挂起消息,忽略:需要交互式身份验证。
无法通过logind重启系统:需要交互式身份验证。
无法启动reboot.target:需要交互式身份验证。
有关详细信息,请参阅系统日志和'systemctl status reboot.target'。
无法打开/ dev / initctl:权限被拒绝
无法与init守护进程通信。
reboot Failed to set wall message, ignoring: Interactive authentication required. Failed to reboot system via logind: Interactive authentication required. Failed to start reboot.target: Interactive authentication required. See system logs and 'systemctl status reboot.target' for details. Failed to open /dev/initctl: Permission denied Failed to talk to init daemon.



然后我使用命令行:


Then I use command line:

#chmod 777 /dev/initctl



这是工作,Ubuntu通过PHP重新启动!!!!。

但重新启动后,我尝试获取的PHP代码,我在上面显示类似的错误。我必须再次#chmod 777 / dev / initctl来保持它的工作。

请帮助我。

P / s:这里我的PHP代码


It's work, Ubuntu reboot through PHP!!!!.
But after reboot, I try php code I gain, I show similar error above. I must #chmod 777 /dev/initctl again to keep it's work.
Please help me.
P/s: here my php code

<?php
        echo "SSH connection: ";
        if (!(


resource = @ ssh2_connect( 192.168.80.137))){
echo [FAILED]< br />;
退出(1);
}
echo [好的]< br />;

echo 身份验证: ;
if (!@ ssh2_auth_password(
resource=@ssh2_connect("192.168.80.137"))) { echo "[FAILED]<br />"; exit(1); } echo "[OK]<br />"; echo "Athentication: "; if (!@ssh2_auth_password(


resource, lam root )){
echo [FAILED] < br />;
退出(1);
}
echo [好的]< br />;

echo Shell: ;
if (!(
resource,"lam","root")) { echo "[FAILED]<br />"; exit(1); } echo "[OK]<br />"; echo "Shell: "; if (!(


这篇关于如何远程重启ubuntu 16.04?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆