gpt4 book ai didi

ssh - 通过 SSH 执行 sudo 的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-03 04:26:34 24 4
gpt4 key购买 nike

我有一个脚本,它使用 sudo 在远程服务器上通过 SSH 运行另一个脚本。但是,当我输入密码时,它会显示在终端上。否则它工作正常。

ssh user@server "sudo script"

执行此操作的正确方法是什么,以便我可以通过 SSH 输入 sudo 的密码,而不会在输入时显示密码?

最佳答案

另一种方法是使用 -t 打开 ssh:

ssh -t user@server "sudo script"

参见man ssh :

 -t      Force pseudo-tty allocation.  This can be used to execute arbi-
trary 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.

关于ssh - 通过 SSH 执行 sudo 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10310299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com