I have a problem with the tool expect under Ubuntu 14.04 LTS. I want to automate ssh logins to some Sophos UTM Firewalls and evelate my rights directly after with "sudo su -" and the correct password. I don't have to worry about plain text passwords, because my script runs directly out of the KeePass URL field (doubleclick executes the script and fills it with the correct passwords via agrument/KeePass {Placeholder} behind the script). I managed to get all of this done, except for having a remote-root shell, which is not executing any commands and "dropping the connection" back to my ubuntu system. So the command I'm trying to run remotely is not excecuting for 4-5 seconds and then gets suddenly executed on the ubuntu system, without telling me what happened.
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!