Batch file 自动将root用户密码提供给";苏";使用批处理文件中的Plink执行

Batch file 自动将root用户密码提供给";苏";使用批处理文件中的Plink执行,batch-file,ssh,putty,plink,Batch File,Ssh,Putty,Plink,我很难像sshpassword那样从根密码行获取自动插入的输入。到目前为止,我有这个,然后它崩溃了。我试图让批处理文件输入ip、ssh密码,然后给suaccess,然后自动输入根密码。什么都行,谢谢 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 P

我很难像
ssh
password那样从根密码行获取自动插入的输入。到目前为止,我有这个,然后它崩溃了。我试图让批处理文件输入ip、ssh密码,然后给
su
access,然后自动输入根密码。什么都行,谢谢

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 R0ot= :

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

exit/b
command.txt中有什么内容

su
echo %R0ot%| plink -t -ssh user@%IP% -pw %Passw0rd% su

首先警告一句:使用密码自动执行
su
,尤其是
su
,通常是个坏主意:

su
设计用于抵抗自动化


无论如何,
su
需要输入密码。
plink
将其输入转发到远程命令输入

因此,您只需将变量作为输入传递给
plink
(请参阅):

您也可以直接在
plink
命令行上执行
su
,避免使用
command.txt

su
echo %R0ot%| plink -t -ssh user@%IP% -pw %Passw0rd% su
-t
是必需的
su
通常会拒绝在没有终端仿真的情况下运行。另一方面,
-t
会给您带来麻烦。例如,使用
-t
时,您可能只需要在
su
提示输入密码时,将密码输入到
plink
。所以你可能需要一个。或者使用黑客解决方案,如延迟输入,请参阅


另一个相关问题,显示了略微不同的方法: