-1

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
CWRules
  • 87
  • 7

2 Answers2

0

Read the error: sudo requires a tty. That is, an interactive shell. You have to find an other way of doing those privileged instructions. For example, you could login as root with a key-based authentication.

MayeulC
  • 1,628
  • 17
  • 24
  • This is supposed to be used for test automation, so using an interactive shell won't work. I'll look into key-based authentication. – CWRules Sep 21 '16 at 19:55
  • technically you could login with a password, but this is a very bad idea security-wise. Maybe the real question here is *why do you need root access*? If for communicating with some devices, udev rules should be enough. – MayeulC Sep 21 '16 at 21:00
0

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]
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I didn't realize the the -m option did that. Adding -t fixed the sudo error. It's still not working, but I think the new issue is due to the script I'm trying to run, not PuTTY. Thanks! – CWRules Sep 22 '16 at 12:59