繁体   English   中英

如何通过远程计算机上的nohup在内部使用sudo运行shell脚本

[英]How to run shell script with sudo inside through nohup on remote machine

我从本地计算机运行了以下命令:

ssh -i key remote_host "nohup sh test.sh > nohup.out 2> nohup.err < /dev/null &"

然后我得到了错误: sudo: sorry, you must have a tty to run sudo

我添加了-tt选项:

ssh -tt -i key remote_host "nohup sh test.sh > nohup.out 2> nohup.err < /dev/null &"

我检查了远程, test.sh没有运行(没有进程ID)。

我拿出nohup ,一切正常,ssh -tt -i键remote_host“ sh test.sh”,但是我需要使用nohup 有人能帮我吗? 非常感谢!

一个remote_host:test.sh脚本:

#!/bin/bash
sudo iptables -A OUTPUT -p tcp --dport 443 -j DROP
sleep 30
sudo iptables -D OUTPUT -p tcp --dport 443 -j DROP

sudo可能试图提示您输入密码。 您需要在remote_host的sudoers文件中设置NOPASSWD,或者可以使用expect

暂无
暂无

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

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