Reputation: 41
I'm having a difficult time getting the input from the root password line to auto plug in just like the ssh
password does. So far I have this, then it crashes. I'm trying to get the batch file to input the ip, ssh password, then give su
access then auto input the root pass. Anything would help thanks!
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
What's in command.txt
:
su
Upvotes: 1
Views: 1896
Reputation: 202642
First a word of warning: Automating su
, particularly su
with a password, is usually a bad idea: Allowing automatic command execution as root on Linux using SSH.
The su
is designed to resist the automation.
Anyway, the su
expects the password on its input. The plink
forwards its input to the remote command input.
So all you need to do is to pass your variable as an input to the plink
(see How to pass user input automatically using plink.exe):
echo %R0ot%| plink -t -ssh user@%IP% -pw %Passw0rd% -m command.txt
You can also execute the su
directly on the plink
commandline, avoid the need for command.txt
:
echo %R0ot%| plink -t -ssh user@%IP% -pw %Passw0rd% su
The -t
is needed su
will typically refuse to run without terminal emulation. On the other hand, -t
can cause you troubles. For example, with -t
you might have to feed the password to plink
only at the moment su
prompts for it. So you may need a expect
-linke tool. Or use a hackish solution, like delaying the input, see Wait between sending login and commands to serial port using Plink.
Another related question, showing slightly different approaches:
Execute sudo command on Linux from plink.exe on Windows
Upvotes: 2