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

喜夏-厌秋 提交于 2019-12-21 16:21:44

问题


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?


回答1:


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



回答2:


Why are you using plink here? In general, you'd use 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: http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter7.html




回答3:


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.



回答4:


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


来源:https://stackoverflow.com/questions/20248009/execute-sudo-command-on-linux-from-plink-exewindows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!