执行“su"使用批处理文件中的 PuTTY Plink [英] Executing "su" with PuTTY Plink from a batch file

查看:71
本文介绍了执行“su"使用批处理文件中的 PuTTY Plink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试获取批处理文件以在 PuTTY/Plink 中也授予我超级用​​户访问权限时遇到问题.我可以自动输入 ip 和密码,但我也想将它自动化到在我运行这个批处理文件时它还会给我 su 访问权限的地方.到目前为止,它运行到我需要手动输入 su 的地步,但我正在尝试自动化,所以我尝试了 -m commands.txt,现在它只是崩溃了.. 在这里寻求任何帮助,谢谢.

I'm having trouble trying to get my batch file to also give me super user access in PuTTY/Plink. I can auto-input the ip and password but I want to also automate it to where it will also give me su access when I run this batch file. So far it runs up to the point where I need to manually enter su but I'm trying to automate that so I tried -m commands.txt and now it just crashes.. Looking for any help here thanks.

这是我目前所拥有的

@echo off
color b
cls
echo What is the IP for the unit?:
set /p IP= :

echo What is the SSH Password for this unit?:
set /p Passw0rd= :

echo What is the Root Password for this unit?:
set /p ro0t= :

start plink.exe -ssh user@%IP% -pw %Passw0rd% -m commands.txt

exit/b

commands.txt 中的内容:

su

推荐答案

su 肯定会提示您出了什么问题.但是您看不到它,因为您在一个立即消失的新控制台窗口中使用 start 启动 plink.删除start,至少在调试问题时.

The su gives you a hint what's wrong, for sure. But you cannot see it because you start plink using start in a new console window that immediately disappears. Remove the start, at least when debugging the problem.

无论如何,您很可能会收到standard in must be a tty"或类似的消息.su 默认需要终端输入密码提示.Plink 用于自动化,而不是交互式使用.因此默认情况下它不会为会话分配伪终端.要强制使用终端,请添加 -t 开关:

Anyway, you most likely get "standard in must be a tty" or a similar message. The su by default needs terminal for the password prompt. The Plink is meant an for an automation, not an interactive use. So it by default does not allocate a pseudo terminal for the session. To force use of the terminal, add -t switch:

plink.exe -t -ssh user@%IP% -pw %Passw0rd% -m commands.txt


一个类似的问题:Sudo"因sudo requires a tty"而失败;从 PuTTY 命令行执行时

作为下一步,您可能希望在 su 内执行更多命令.为此,请参阅使用 Plink 执行 (sudo) 子命令.

As a next step, you will probably want to execute further commands within su. For that see Executing (sudo) subcommands using Plink.

尽管请注意,通常使用密码自动化 su,尤其是 su,通常是一个坏主意:允许在 Linux 上使用 SSH 以 root 身份自动执行命令.

Though note that in general automating su, particularly su with a password, is usually a bad idea: Allowing automatic command execution as root on Linux using SSH.

这篇关于执行“su"使用批处理文件中的 PuTTY Plink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆