Skip to content
Blog Toggle SSH Session using SSH Escape Character

Toggle SSH Session using SSH Escape Character

When you’ve logged on to the remotehost using ssh from the localhost, you may want to come back to the localhost to perform some activity and go back to remote host again. In this case, you don’t need to disconnect the ssh session to the remote host. Instead, follow the steps below.

1. Login to remotehost from localhost:

dipin@linuxgeek:~$ ssh user@remotehost

2. Now you will be connected to the remotehost and your prompt will read:

remotehost$

3. Now to come back to the localhost temporarily, type the escape character ~ followed by Control-Z.
You won’t see the ~ character on the screen immediately after you type it, until you press and press enter. So, on the remotehost enter the following key strokes: ~

remotehost$ ~^Z
[1]+ Stopped ssh user@remotehost

dipin@linuxgeek:~$

4. Now you are back to the localhost and the ssh remotehost client session runs as a typical UNIX background job, which you can check as shown below:

dipin@linuxgeek:~$ jobs
[1]+ Stopped ssh user@remotehost

5. Now you can go back to the remotehost ssh without entering the password again by bringing the background ssh remotehost session job to foreground on the localhost.

dipin@linuxgeek:~$ fg %1
ssh user@remotehost

remotehost$

Enjoy!.

2 thoughts on “Toggle SSH Session using SSH Escape Character”

  1. You can just open ssh in screen. This way you can have as many ssh sessions as you want in just one terminal.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.