Saw a solution from online and got it working, though I'm really not yet fully aware on the add ons :-)
connect.sh
Code:
#!/usr/bin/expect -f
set host [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
set user2 [lindex $argv 3]
set password2 [lindex $argv 4]
spawn ssh -qt "$user\@$host"
expect "password:"
send "password\r";
send -- "sudo su - $user2\r"
expect -gl {[sudo] password for pogi_ako:}
send "password\r"
interact
Tried and execute:
Code:
pogi_ako@MY_CYGWIN ~
$ ./connect.sh target_host pogi_ako password user password
spawn ssh -qt pogi_ako@target_host
pogi_ako@target_host's password:
Last login: Thu Oct 8 01:19:07 2015 from 192.168.0.101
[pogi_ako@target_host ~]$ sudo su - user
[sudo] password for pogi_ako:
[user@target_host ~]$
From alias
Code:
alias target_host='echo "connecting on to target_host" ; ./connect.sh target_host pogi_ako password user password'
Test alias from my terminal
Code:
pogi_ako@MY_CYGWIN ~
$ target_host
connecting on to target_host
spawn ssh -qt pogi_ako@target_host
pogi_ako@target_host's password:
Last login: Thu Oct 8 02:42:35 2015 from 192.168.0.101
[pogi_ako@target_host ~]$ sudo su - user
[sudo] password for pogi_ako:
[user@target_host ~]$