CWRules CWRules - 1 year ago 109
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]

is a .txt file containing the commands I want to run. The issue is that one of the commands requires
, 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
instead of
, and it made no difference.

I can't change the
setting in my
file for security reasons, which is the only solution I've been able to find. Is there another option?

Answer Source

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download