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
Jumphost2 --> and then -->
Jumphostx is sshkeygen enabled but with passphrase for eg:
remote-host is not sshkeygen enabled eg:
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 188.8.131.52 Port 2222 Host jump1-centos01 Hostname 184.108.40.206 Port 22 ProxyCommand ssh -W %h:%p jump1-centos01-temporary Host remote-host Hostname 220.127.116.11 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 "userpass\r" expect "Enter passphrase for key '/root/.ssh/id_rsa':" send "userpass\r" expect "Password:" send "remotepass\r" interact