Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 856
Paul Avatar asked Nov 27 '13 16:11

Paul


People also ask

How do I run a sudo command in Windows?

There is no sudo command in Windows. The nearest equivalent is "run as administrator." You can do this using the runas command with an administrator trust-level, or by right-clicking the program in the UI and choosing "run as administrator."

How do I use plink on Windows?

1 Using Plink for interactive logins. To make a simple interactive connection to a remote server, just type plink and then the host name: Z:\sysosd>plink login.example.com Debian GNU/Linux 2.2 flunky.example.com flunky login: You should then be able to log in as normal and run a session.

How does plink EXE work?

Plink is a command line application. This means that you cannot just double-click on its icon to run it and instead you have to bring up a console window. In Windows 95, 98, and ME, this is called an 'MS-DOS Prompt', and in Windows NT, 2000, and XP, it is called a 'Command Prompt'.

How do I run a sudo script?

Running a Specific Script as Another User. Before we can execute scripts as other users with sudo, we'll need to add the current user to the sudoers file. To do that, we'll use the visudo command to safely edit the /etc/sudoers file. The command above echo the rule and pipe the rule into the visudo command.


1 Answers

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
like image 162
user2948547 Avatar answered Sep 19 '22 23:09

user2948547