execute sudo command on linux from plink.exe[windows]

i know that the question is old but this can help

you can execute plink (putty tools)

plink -v -ssh -m "path/to/commands.txt" -l usertologin -pw PASSWORDSERVER

commands.txt:

echo -e "PASSWORD\n" | sudo -S cat /etc/passwd

sudo -S is to receive the password from stdin and with the echo -e "password\n" is to pass the password (and \n is like to press intro -new line- )

the same way you can execute the passwd command:

> echo -e "OLDPASSWORD\nNEWPASSWORD\nNEWPASSWORD" | passwd

Why are you using a plink here? In general, you'd use a plink to call a non-interactive script on a remote host. If you want to do interactive stuff, (like edit a file), just ssh to the server (either from your shell, using 'ssh' client on Linux, or by running putty on Windows), then edit the file.

More info on plink, and some examples, can be found here.


Why Plink ? use SSH instead. Also SSH would need -t option for sudo commands. From ssh man page:

 -t      Force pseudo-tty allocation.  This can be used to execute arbitrary screen-based programs on a remote
         machine, which can be very useful, e.g. when implementing menu services.  Multiple -t options force tty
         allocation, even if ssh has no local tty.