"Sudo"失败并显示"sudo require tty";从PuTTY命令行执行时 [英] "Sudo" fails with "sudo requires a tty" when executed from PuTTY command line
问题描述
我正在尝试使用PuTTY在远程CentOS计算机上运行一些命令.我正在使用以下命令:
I'm trying to run some commands on a remote CentOS machine using PuTTY. I'm using the following command:
putty.exe -ssh [IP] -l [user] -pw [password] -m [Script]
其中 [Script]
是一个 .txt 文件,其中包含我要运行的命令.问题是其中一个命令需要 sudo
,当PuTTY尝试运行它时,我会收到错误消息:
Where [Script]
is a .txt file containing the commands I want to run. The issue is that one of the commands requires sudo
, and when PuTTY tries to run it I get an error:
sudo 需要一个 tty
sudo requires a tty
让我感到困惑的是,如果我在没有提供脚本的情况下启动会话,然后手动运行脚本中的命令,则效果很好.我尝试使用 -load
而不是 -ssh
,但这没什么区别.
The thing that's confusing me is that if I start the session without giving a script, then run the commands from the script manually, it works fine. I've tried using -load
instead of -ssh
, and it made no difference.
出于安全原因,我无法更改 sudoers
文件中的 requiretty
设置,这是我唯一能找到的解决方案.还有其他选择吗?
I can't change the requiretty
setting in my sudoers
file for security reasons, which is the only solution I've been able to find. Is there another option?
推荐答案
sudo
需要TTY/交互式会话.
The sudo
requires TTY/interactive session.
相反,PuTTY/Plink -m
开关默认情况下使用非交互式会话.
On the contrary the PuTTY/Plink -m
switch uses non-interactive session by default.
使用 -t
开关以覆盖它.
Use the -t
switch to override that.
putty.exe -ssh [IP] -l [user] -pw [password] -t -m [Script]
这篇关于"Sudo"失败并显示"sudo require tty";从PuTTY命令行执行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!