#StackBounty: #scripting #python #ssh-tunneling Advance autologin via 2 jumphost/passphrase

Bounty: 50

I need to find a way to autologin on Remote Machine. There are several way in which we can do this but this is little tricky for me.

Auto Login to a remote machine and execute command or script and redirect the output in the local system file.

ssh remote-host < ./script >> storageinfo_$date.txt

But the hard part is to we can’t directly connect to the remote host; we need to first connect to the Jumphost1 –> Jumphost2 –> and then –> remote-host

Jumphostx is sshkeygen enabled but with passphrase for eg: userpass
remote-host is not sshkeygen enabled eg: remotepass

We used to do this with .ssh/config file in the below manner. This was successful so far in the test env. But we are not supposed to install expect in the live env.

# cat .ssh/config

Host jump1-*
    User ldap-user
    IdentityFile ~/.ssh/id_rsa
    ForwardAgent yes
    ServerAliveInterval 60
    ServerAliveCountMax 12

Host jump1-centos01-temporary 
    Hostname 13.1.2.19
    Port 2222

Host jump1-centos01        
    Hostname 1.2.1.18
    Port 22
    ProxyCommand ssh -W %h:%p jump1-centos01-temporary

Host remote-host
    Hostname 12.1.1.8
    ProxyCommand ssh -W %h:%p jump1-centos01
    User root

ssh connection with expect and send patern

# cat expect.sh 

#!/usr/bin/env expect
set timeout 7
set date [exec date "+%d-%B-%Y"]

spawn sh -c "ssh va1ap-vsns0001n < ./isi.py > storageinfo_$date.txt"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "r"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "userpassr"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "userpassr"
expect "Password:"
send "remotepassr"
interact


Get this bounty!!!