7
votes

If I execute the plink command

plink  user@192.168.1.12   sudo nano /etc/hosts

Upon typing the password when prompted, I am getting

sudo: no tty present and no askpass program specified

Sorry, try again.

sudo: no tty present and no askpass program specified

Sorry,try again.

sudo: no tty present and no askpass program specified

Sorry, try again.

sudo: 3 incorrect password attempts

How to execute the sudo command from plink? Or is there any alternatives?

4

4 Answers

11
votes

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
3
votes

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.
3
votes

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.

0
votes

I needed to make some folders and set perms. These blocks worked for me in PowerShell to automate. Whoever up there that is suggesting to just use SSH hopefully has figured out that is currently not the right solution. Reduction of manual process should be everyone's goal.

$null = iex "cmd /c $plinkpath -ssh -l $linuser -pw $linpass $computername `"echo $linpass | sudo -S mkdir $puppetfolder`"" *>&1

$null = iex "cmd /c $plinkpath -ssh -l $linuser -pw $linpass $computername `"echo $linpass | sudo -S chmod o+wx $puppetfolder`"" *>&1