2

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.

this is what I have so far

@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

what in the commands.txt:

su
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
drod2030
  • 41
  • 5

1 Answers1

2

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.

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

A similar question: "Sudo" fails with "sudo requires a tty" when executed from PuTTY command line


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


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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992