Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I close a frozen SSH session?

Tags:

ssh

Sometimes an SSH session to a remote server will freeze indefinitely due to bad internet connectivity. Is it possible to close the session without closing the terminal?

like image 864
Jian Avatar asked Mar 11 '15 07:03

Jian


People also ask

How do I get out of a stuck SSH session?

If you want to terminate an interactive OpenSSH session which is stuck and cannot be exited by entering exit or Ctrl D into a shell on the remote side, you can enter ~ followed by a dot . . To be sure to enter the escape character at the beginning of an input line, you should press Enter first.

Does SSH keep running after disconnect?

Option 2: bg + disown. If you want to "background" already running tasks, then Ctrl + Z then run bg to put your most recent suspended task to background, allowing it to continue running. disown will keep the process running after you log out.

How do you end a session in Linux?

Use 'SIGKILL' or '9' with the kill command to terminate a process. For instance: All users need to be logged out of system before we trigger a monthly job. To kill multiple ssh sessions running in system.

How do I disconnect a putty session?

To end the Putty session, type the logout command such as exit or logout. This command might vary between servers. You can close the session by using the Close button.


2 Answers

Press the following three keys:

  1. Enter
  2. ~ (tilde)
  3. . (period)

This is the "disconnect" function as described in the ESCAPE CHARACTERS section of the ssh man page.

like image 60
Jian Avatar answered Oct 27 '22 22:10

Jian


In this post, geekosaur suggests we use the escape sequences as follows: "To kill the current session hit subsequently Enter ↵, ~, ..

More of these escape sequences can be listed with Enter ↵, ~, ?:

Supported escape sequences:   ~.  - terminate session   ~B  - send a BREAK to the remote system   ~R  - Request rekey (SSH protocol 2 only)   ~#  - list forwarded connections   ~?  - this message   ~~  - send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.) 

You can close the list of Escape sequences by hitting Enter ↵.

Notice that because hitting ~~ causes ssh to send the ~ instead of intercepting it, you can address N nested ssh connections by hitting ~ N times. (This only applies to ~s that directly follow an Enter ↵.) That is to say that Enter ↵~~~~~. terminates an ssh session 5 layers deep and keeps the other 4 intact."

like image 43
Pablo Rivas Avatar answered Oct 27 '22 22:10

Pablo Rivas