我试过这个:
#!bin/bash
ssh [email protected] /cdn-cgi/l/email-protection 'sudo /etc/init.d/script restart'
但我收到这个错误:
sudo: no tty present and no askpass program specified
我怎样才能运行该脚本?现在,当我需要运行该脚本时,我会执行以下步骤:
ssh [email protected] /cdn-cgi/l/email-protection
sudo /etc/init.d/script restart
但我不想一直手动登录远程服务器,然后输入重新启动命令。
我可以编写可以运行的本地脚本,这样我只需要输入密码,它就会运行远程脚本并重新启动进程吗?
您可以使用-t
选项中ssh
命令到附加一个伪 tty和你的ssh
命令:
ssh -t -t [email protected] /cdn-cgi/l/email-protection 'sudo /etc/init.d/script restart'
As per man ssh
:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)