The SSH protocol in Linux is used to manage remote systems. It works by allowing you to securely log in to a remote device, which could be another Linux system, firewall, router, etc. When you are finished with your remote administration, it will be time to disconnect from the SSH connection. In this tutorial, you will see various ways to disconnect from an SSH connection on a Linux system. You will also learn the escape characters to exit from an SSH session, which comes in handy if you encounter a hung system that you have an SSH connection into and need to return to your local terminal.
In this tutorial you will learn:
- How to disconnect from an SSH session
- How to disconnect from a hung SSH connection
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Methods for how to disconnect from SSH session
- The first way to disconnect from an SSH session is with the
exitcommand. Issue this command on the remote terminal that you are currently logged in to.
- The second way to disconnect from an SSH session is with the
logoutcommand. This will work on Linux systems but may not work for other devices with different operating systems. But usually it will work.
- The third way to disconnect from an SSH session is with the
Ctrl + Dkeyboard combination, which is the end of file command.
- If your SSH connection is frozen, the three methods above may not work for you. In that case, you can type
~.to close the SSH session and return to your local command line terminal. This works as an escape character for SSH connections.
In this tutorial, you saw how to disconnect from an SSH session on a Linux system. SSH is an essential tool for remote adminitration, so knowing how to logout will be necessary whenever you are ready to close your connection. The two methods we recommend remembering are
~.escape characters, just in case you get a hung connection.