问题很简单。
通过ssh关闭网络中的计算机所必须使用的脚本是什么。
通常我会去命令行并:
ssh desktop
delik@desktop's password:
delik@desktop:~$ sudo shutdown -P 0
为了开机,我创建了一个文件并写道:
wakeonlan xx:xx:xx:xx:xx:xx
并给它可执行位
以这种方式打开电源仅需双击即可。我能做同样的事情来关机吗?
假设要在remote.host中使用的用户与在local.host中使用的用户相同
,则必须首先授权您的local.host以不带密码的方式连接到remote.host。
为此,您必须:(如此处所述)
sudo apt-get install ssh
在本地主机上,输入以下命令:
ssh-keygen
您应该将生成的密钥保存在:
/home/yourusername/.ssh/id_rsa
按两次Enter键,将密码短语留空。
Your identification has been saved in /home/yourusername/.ssh/id_rsa.
Your public key has been saved in /home/yourusername/.ssh/id_rsa.pub.
The key fingerprint is:
XX:XX:XX:xX:XX:xX:XX:XX:XX:XX:XX:XX:XX:XX yourusername@local-host
yourusername@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
yourusername@remote-host's password:
Now try logging into the machine, with "ssh remote-host", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
注意:ssh-copy-id将密钥附加到远程主机的/ home /您的用户名/.ssh/authorized_key
ssh remote-host
[email protected]:~$
无需密码即可访问远程主机。成功!
现在,您必须能够在没有密码的情况下执行sudo shutdown -P 0。
这样,用户“ yourusername ”可以在不询问密码的情况下执行关闭命令。
登录到远程主机。
ssh remote.host
跑步:
sudo visudo
通过运行visudo,它会导致编辑/ etc / sudoers。
将以下行添加到该文件。
yourusername ALL = NOPASSWD: /sbin/shutdown
完成后,回到您的local.host
创建一个新的空文件并粘贴此行,修改remote.host的名称
ssh remote.host sudo shutdown -P 0
保存并关闭它,转到“属性”幻灯片,然后单击“允许”,然后将该文件作为程序执行
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句