从 plink.exe[windows] 在 linux 上执行 sudo 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20248009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
execute sudo command on linux from plink.exe[windows]
提问by Paul
If I execute the plink command
如果我执行 plink 命令
plink [email protected] sudo nano /etc/hosts
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
sudo:不存在 tty 且未指定 askpass 程序
抱歉,请再试一次。
sudo:不存在 tty 且未指定 askpass 程序
抱歉,请再试一次。
sudo:不存在 tty 且未指定 askpass 程序
抱歉,请再试一次。
sudo:3 次错误的密码尝试
How to execute the sudo command from plink? Or is there any alternatives?
如何从 plink 执行 sudo 命令?或者有其他选择吗?
采纳答案by user2948547
i know that the question is old but this can help
我知道这个问题很旧,但这可以提供帮助
you can execute plink (putty tools)
你可以执行plink(腻子工具)
plink -v -ssh -m "path/to/commands.txt" -l usertologin -pw PASSWORDSERVER
plink -v -ssh -m "path/to/commands.txt" -l usertologin -pw PASSWORDSERVER
commands.txt:
命令.txt:
echo -e "PASSWORD\n" | sudo -S cat /etc/passwd
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- )
sudo -S 是从 stdin 接收密码,使用 echo -e "password\n" 是传递密码(而 \n 就像按 intro -new line- )
the same way you can execute the passwd command:
与执行 passwd 命令的方式相同:
> echo -e "OLDPASSWORD\nNEWPASSWORD\nNEWPASSWORD" | passwd
回答by Mark J. Bobak
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.
你为什么在这里使用 plink?通常,您会使用 plink 在远程主机上调用非交互式脚本。如果您想进行交互式操作(例如编辑文件),只需 ssh 到服务器(从您的 shell,在 Linux 上使用“ssh”客户端,或在 Windows 上运行 putty),然后编辑文件。
More info on plink, and some examples, can be found here: http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter7.html
有关 plink 的更多信息和一些示例,可以在这里找到:http: //the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter7.html
回答by slayedbylucifer
Why Plink ? use SSH instead. Also SSH would need -t
option for sudo
commands.
From ssh man page:
为什么是普林克?请改用 SSH。SSH 还需要命令-t
选项sudo
。从 ssh 手册页:
-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.
回答by Christopher
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.
我需要制作一些文件夹并设置烫发。这些块在 PowerShell 中为我工作以实现自动化。那些建议只使用 SSH 的人希望已经发现目前不是正确的解决方案。减少人工流程应该是每个人的目标。
$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