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
[email protected]'s password:
Last login: Wed Dec  4 05:51:28 2013 from
[email protected] [~]#


Login to remotehost-2 from remotehost-1

[email protected] [~]# ssh [email protected] -p 2244
The authenticity of host '[]:2244 ([]: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 '[]:2244' (RSA) to the list of known hosts.
[email protected]'s password:
Last login: Wed Dec  4 05:50:03 2013 from
[email protected] [~]#


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 and press enter.

[email protected] [~]# ~^Z [suspend ssh]

[1]+  Stopped                 ssh [email protected] -p 2244
[email protected] [~]# 


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

[email protected] [~]# jobs
[1]+  Stopped                 ssh [email protected] -p 2244
[email protected] [~]#


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.

[email protected] [~]# fg %1
ssh [email protected] -p 2244

[email protected] [~]#

That’s it.

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

Please support the site
By clicking any of these buttons you help our site to get better