sudo will only run a program as a different user if one of these 3 conditions has been met (as far as passwords are concerned):
- the NOPASSWD option is specified
- the user entered the correct target password
- the user entered the correct source password
Since options 2 and 3 require a TTY (sudo won't read from a pipe) it won't run if it can't find one. Check your script if at any point you're running a script remotely using ssh, as it's possible that it won't allocate a TTY for a non-interactive remote command.
本文详细介绍了使用sudo命令进行权限提升的三个条件,并解释了在没有指定NOPASSWD选项时,为何需要通过TTY输入正确的源或目标密码。此外,还特别说明了在远程使用SSH执行脚本时可能遇到的问题。
1万+

被折叠的 条评论
为什么被折叠?



