2

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!

  • Will the connection drop by just running ssh -t loginuser@192.168.1.254 "sudo su -"? (This command works for me without dropping connection) – P.-H. Lin Apr 18 '16 at 7:47
  • No, it won't drop if i'll enter my passwords manually. The described problem only occurs when automating the password prompt via script. – Nyctophilia Apr 18 '16 at 7:52
  • 2
    If you want a "responsive" remote shell, don't you need an interact command after completing the login exchange? – steeldriver Apr 18 '16 at 11:47
  • You made my day. It's working now! – Nyctophilia Apr 18 '16 at 14:46
  • duplicate of superuser.com/q/1066734/4714 – glenn jackman Apr 18 '16 at 16:09
0

I had a problem similar to this. The issue was that my remote .bashrc file had some lines to do nothing if not running interactively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.