Toggle SSH Session via SSH Escape Character
Most of the people don’t know this option, its very useful for server administrator.
You can assume the scenario : you are having 2 server’s both server having the firewall, you are trying to Login remotehost-2 with wrong password more then 3 times the public IP (Static IP) was blocked on remotehost-2 that time you have no option to access the remotehost-2 without removing the IP from remotehost-2 firewall. The quick and easy way to do it by login from remotehost-1 to remotehost-2 and perform the action.
You can also use the SSH Escape Character to work both server with single ssh session without login and logout both server.
When you’ve logged on to the remotehost-2 using ssh from the remotehost-1, you may want to come back to the remotehost-1 to perform some activity and go back to remotehost-2 again. In this case, you don’t need to disconnect the ssh session to the remotehost-2. For better understanding follow the below steps.
Now, I’m in remotehost-1
login as: root firstname.lastname@example.org's password: Last login: Wed Dec 4 05:51:28 2013 from 220.127.116.11 root@remotehost-1 [~]#
Login to remotehost-2 from remotehost-1
root@remotehost-1 [~]# ssh email@example.com -p 2244 The authenticity of host '[18.104.22.168]:2244 ([22.214.171.124]:2244)' can't be established. RSA key fingerprint is 84:96:3e:b9:5e:95:a2:76:69:3f:0f:95:fb:10:09:7d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[126.96.36.199]:2244' (RSA) to the list of known hosts. firstname.lastname@example.org's password: Last login: Wed Dec 4 05:50:03 2013 from 188.8.131.52 root@remotehost-2 [~]#
To come back to the remotehost-1 temporarily, type the escape character ~ and (Control+Z).
Note : When you type ~ you will not see that immediately on the screen until you press
root@remotehost-2 [~]# ~^Z [suspend ssh] + Stopped ssh email@example.com -p 2244 root@remotehost-1 [~]#
Now you are back to the remotehost-1 and the ssh remotehost-2 client session runs as a typical UNIX background job, which you can check as shown below
root@remotehost-1 [~]# jobs + Stopped ssh firstname.lastname@example.org -p 2244 root@remotehost-1 [~]#
You can go back to the remotehost-2 ssh without entering the password again by bringing the background ssh remotehost-2 session job to foreground on the remotehost-1.
root@remotehost-1 [~]# fg %1 ssh email@example.com -p 2244 root@remotehost-2 [~]#