Durch die Automatisierung der SSH-Anmeldung wird die Remote-Shell nicht mehr reagiert, und sie wird ohne Fehler auf das Client-Terminal zurückgesetzt.

477
Nyctophilia

Ich habe ein Problem mit dem Tool unter Ubuntu 14.04 LTS. Ich möchte SSH-Anmeldungen für einige Sophos UTM Firewalls automatisieren und meine Rechte direkt danach mit "sudo su -" und dem richtigen Kennwort auswerten. Ich muss mich nicht um Klartextpasswörter kümmern, da mein Skript direkt aus dem KeePass-URL-Feld ausgeführt wird (Doppelklick führt das Skript aus und füllt es mit den korrekten Passwörtern über agrument / KeePass hinter dem Skript). Ich habe es geschafft, all das zu erledigen, außer dass ich eine Remote-Root-Shell hatte, die keine Befehle ausführt und die Verbindung zu meinem Ubuntu-System zurückbringt. Der Befehl, den ich versuche, aus der Ferne auszuführen, wird nicht für 4-5 Sekunden ausgeführt und dann auf dem Ubuntu-System plötzlich ausgeführt, ohne mir zu sagen, was passiert ist.

What do I have to do, to have fully functioning remote-shell? SSH-Keys and direct root-login is not a solution for me, as we are having too much Sophos UTMs out there.

Explained stuff happening:

sshtool.sh: #!/usr/bin/expect -f spawn sshpass -pPASSWORD ssh -t loginuser@192.168.1.254 "sudo su -" expect -- "oot's password:" send "PASSWORD\r" expect -- "/root #" expect eof    What happens in the terminal: vct@vct-virtual-machine:~$ ./sshtool.sh spawn sshpass -pPASSWORD ssh -t loginuser@192.168.1.254 sudo su - root's password: utm:/root # whoami # *enter* # not reacting for 4-5 seconds vct@vct-virtual-machine:~$ whoami vct vct@vct-virtual-machine:~$ 

Changing the script like this, doesn't help with the dropping connection issue:

sshtool.sh: #!/usr/bin/expect -f spawn ssh loginuser@192.168.1.254 expect -- "password:" send "PASSWORD\r" expect -- "/home/login > " send -- "sudo su -\r" expect -- "oot's password:" send "PASSWORD\r" expect -- "/root #" send -- "whoami\r" expect eof   vct@vct-virtual-machine:~$ ./sshtool.sh spawn ssh loginuser@192.168.1.254 loginuser@192.168.1.254's password: Last login: Mon Apr 18 09:14:41 2016 from 192.168.1.44   Sophos UTM (C) Copyright 2000-2015 Sophos Limited and others. All rights reserved. Sophos is a registered trademark of Sophos Limited and Sophos Group. All other product and company names mentioned are trademarks or registered trademarks of their respective owners.  For more copyright information look at /doc/astaro-license.txt or http://www.astaro.com/doc/astaro-license.txt  NOTE: If not explicitly approved by Sophos support, any modifications done by root will void your support.  <M> loginuser@utm:/home/login > sudo su - root's password: # Following "whoami" directly executed by the script itself works fine <M> utm:/root # whoami root # After 4-5 seconds, it's dropping the connection again <M> utm:/root # vct@vct-virtual-machine:~$ 

Thanks in advance!

1
Duplikat von http://askubuntu.com/q/758595/10127 glenn jackman vor 8 Jahren 0

1 Antwort auf die Frage

1
Jakuje

If you want a "responsive" remote shell, you need an interact command after completing the login exchange. Something like this:

#!/usr/bin/expect -f spawn sshpass -pPASSWORD ssh -t loginuser@192.168.1.254 "sudo su -" expect -- "oot's password:" send "PASSWORD\r" expect -- "/root #" interact