Plink wechselt den Benutzer nicht mit dem Befehl su

1074
Gopi Krishnan

Ich verbinde mich wie folgt mit einem Server über plink:

plink -ssh -l username -pw password example.host.com -m C:\Putty\input.txt > C:\Putty\output.txt 

input.txt enthält

whoami su - newsuser whoami 

output.txt enthält

username username 

SU funktioniert nicht über Plink.

Wenn Sie den gleichen Befehl in putty verwenden, funktioniert es gut und die Ausgabe wird als "newsuser" ausgegeben .

Linux PuTTY - automatisieren Sie su für Passwortprobleme

Ich habe die obige Lösung ausprobiert, aber sie funktioniert nicht für mich.

Vielen Dank

1

1 Antwort auf die Frage

2
Martin Prikryl

First, it does not work the way you think.

The commands in the script are executed in sequence. The su (had it succeeded) would execute an interactive shell session and wait for user input (commands). Only once the su exists, the second whoami runs (showing username).


Anyway, your su does not work indeed.

First, the su for sure outputs some error message. What is that? You capture only a standard output in your commands. Capture an error output too (2>&1). It most likely fails, because su may need an interactive terminal, while Plink with -m switch uses non-interactive terminal by default. Adding -t switch helps in this case.


Note that automating su is generally a bad idea. If you need to run some commands that require root privileges, a better solution is to associate a dedicated private key with the commands in sudoers file. And then use sudo and private key in the Plink.

Wenn ich -t verwende, fehlt seine Anzeige als input.txt-Datei. Ich habe mit vollem Pfad versucht \, \\, aber immer noch den gleichen Fehler Gopi Krishnan vor 6 Jahren 0
Sie haben anscheinend "-t" anstelle von "-m" verwendet. Sie müssen beide verwenden. Lesen Sie die Dokumentation! Martin Prikryl vor 6 Jahren 0