【问题标题】:Executing "su" with PuTTY Plink from a batch file从批处理文件中使用 PuTTY Plink 执行“su”
【发布时间】:2021-03-31 13:59:14
【问题描述】:

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

这是我目前所拥有的

@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

【问题讨论】:

    标签: batch-file ssh putty plink


    【解决方案1】:

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

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

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

    类似问题:"Sudo" fails with "sudo requires a tty" when executed from PuTTY command line


    下一步,您可能希望在 su 内执行更多命令。为此请参阅Executing (sudo) subcommands using Plink


    但请注意,一般而言,自动化 su,尤其是带有密码的 su,通常是个坏主意:Allowing automatic command execution as root on Linux using SSH

    【讨论】:

      猜你喜欢
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 2012-12-26
      • 1970-01-01
      相关资源
      最近更新 更多