The Computer Oracle

How do I exit an SSH connection?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC B Schuberts Piano Sonata No 16 D

--

Chapters
00:00 Question
00:40 Accepted answer (Score 427)
03:01 Answer 2 (Score 331)
05:03 Answer 3 (Score 33)
05:19 Answer 4 (Score 13)
05:34 Thank you

--

Full question
https://superuser.com/questions/467398/h...

Accepted answer links:
[end-of-file]: https://en.wikipedia.org/wiki/End-of-fil...
[the SSH documentation]: https://linux.die.net/man/1/ssh

Answer 2 links:
[the OpenBSD man page on ssh]: http://www.openbsd.org/cgi-bin/man.cgi?q...
[www.openssh.org]: http://www.openssh.org/manual.html

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #ssh #virtualbox

#avk47



ANSWER 1

Score 343


Short answer: Type exit

If that doesn't work, however...

SSH Escape Character and Disconnect Sequence

Most SSH implementations implement an escape character for interactive sessions, similar to telnet's Ctrl-] combination. The default SSH escape character is ~, entered at the beginning of a line.

If you want to terminate an interactive OpenSSH session which is stuck and cannot be exited by entering exit or CtrlD 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. So the following sequence will in most cases terminate an SSH session:

Enter~.

Other Escape Sequences

OpenSSH, for example, offers other escape sequences besides ~.. Entering ~? during a session should give you a list. Some examples:

  • ~ followed Ctrl-Z suspends the session,
  • ~& puts it directly into background,
  • ~# gives a list of forwarded connections in this session.
  • If you want to simply enter a tilde at the beginning of a line, you have to double it: ~~.

The escape character can be changed using the command line option -e. If you set the special value -e none, escaping is disabled and the session is fully transparent.

See also the OpenBSD man page on ssh (which is referenced from www.openssh.org) under the -e command line option




ANSWER 2

Score 34


Do you want to exit the SSH shell?

You can type exit and hit Enter, or use Ctrl+D




ANSWER 3

Score 13


Just type exit or logout (then hit Enter of course) both will work.




ANSWER 4

Score 12


These are the supported characters which provide various options with which you can play around with ssh.

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 recognized only immediately after a newline.) You can close the list of Escape sequences by hitting Enter.