How to disconnect from SSH connection

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
Disconnecting from an SSH session on Linux
Disconnecting from an SSH session on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software OpenSSH
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Methods for how to disconnect from SSH session



  1. The first way to disconnect from an SSH session is with the exit command. Issue this command on the remote terminal that you are currently logged in to.
    $ exit
    
  2. The second way to disconnect from an SSH session is with the logout command. This will work on Linux systems but may not work for other devices with different operating systems. But usually it will work.
    $ logout
    
  3. The third way to disconnect from an SSH session is with the Ctrl + D keyboard combination, which is the end of file command.
  4. 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.

Closing Thoughts




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 exit and the ~. escape characters, just in case you get a hung connection.



Comments and Discussions
Linux Forum