CWRules CWRules - 2 months ago 7
Linux Question

"Sudo" fails with "sudo requires a tty" when executed from PuTTY command line

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]


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 requires a tty


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.

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?

Answer

The sudo requires TTY/interactive session.

On the contrary the PuTTY/Plink -m switch uses non-interactive session by default.

Use the -t switch to override that.

putty.exe -ssh [IP] -l [user] -pw [password] -t -m [Script]
Comments