Search code examples
linuxwindowsbashubuntuputty

Execute sudo command on Linux from plink.exe on Windows


If I execute the plink command

plink  [email protected]   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?


Solution

  • 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