Network security

How to Exit SSH: 5 Ways to Close a Session (and a Frozen One)

Type exit to close a normal SSH session. If the session is frozen, press Enter, then ~ and . to drop the connection from the client side.

Cysoro Security TeamPublished · 8 min read
NETWORK SECURITYExit SSHcleanly, every timeexit, Ctrl+D, and the ~. escapefor frozen sessionsuser@server:~$ exitlogoutConnection to server closed.user@local:~$ _Frozen? Enter ~ .client-side escapeCYSORO • cysoro.com
Quick answer

To exit SSH, type exit and press Enter in the remote shell, or press Ctrl+D on an empty prompt. If the session is frozen and ignores input, press Enter, then tilde (~), then a full stop (.), and the OpenSSH client closes the connection immediately. Closing the terminal window also works, but it is less clean than these methods.

Key takeaways

  • Type exit or press Ctrl+D to close a responsive SSH session cleanly.
  • For a frozen session, press Enter, then ~. — the OpenSSH escape sequence closes it from the client side.
  • Use tmux, screen or mosh if you want your work to survive a dropped connection.

You connected to a server, did your work, and now you want out. In most cases one word does it — but when the session freezes, that word never reaches the server, and you need a different trick.

How do I exit an SSH session?

Type exit and press Enter. That closes the remote shell, which ends the SSH connection and returns you to your local prompt, usually with a Connection to host closed message.

This is the standard way out, and it works on Linux, macOS and Windows, in Bash, Zsh and most other shells. It is the method administrators use most, and the one to reach for first.

A typical session looks like this:

user@server:~$ exit
logout
Connection to server closed.
user@local:~$

If you see that, you are done. The connection is closed and your local terminal is back.

What are the ways to exit a responsive SSH session?

There are three clean ways to leave a session that is still responding: exit, logout, and Ctrl+D. All three close the remote shell and end the connection.

MethodHow to use itWhen to use it
exitType exit, press EnterAlways — the standard, reliable way out
logoutType logout, press EnterLogin shells; fails in a subshell or non-login shell
Ctrl+DPress Ctrl+D on an empty promptQuick exit with no typing; sends end-of-file to the shell
~.Press Enter, then ~, then .Frozen sessions only; closes the connection from the client
Close the windowClose the terminal window or tabLast resort; less clean than the methods above

1. The exit command

Type exit at the remote prompt and press Enter. The shell ends, the SSH server closes the connection, and your local prompt returns. It works in every shell and on every operating system.

2. The logout command

Type logout and press Enter. An SSH session is normally a login shell, so logout works the same way as exit there. It can fail if you are in a subshell — for example after running bash inside your session — because that inner shell is not a login shell. In that case, use exit to leave the subshell first, then logout or exit again.

3. Ctrl+D

Press Ctrl+D on an empty prompt line. This sends an end-of-file signal to the shell, which exits just as if you had typed exit. It is the fastest option when your hands are already on the keyboard. If the shell is waiting for input from a command, such as a read prompt, Ctrl+D ends that command first — press it again to exit the shell.

Three clean ways out of a responsive sessionexitType exit, press EnterWorks everywhere,every shell, every OSUse this firstlogoutType logout, press EnterLogin shells only;fails in a subshellSame result as exitCtrl+DPress Ctrl+D at a promptSends end-of-fileto the shellFastest, no typingAll three close the remote shell — and closing the shell closes the connection.
Three clean ways to exit a responsive SSH session. Illustration by Cysoro.

How do I exit a frozen SSH session?

Press Enter, then tilde (~), then a full stop (.). This is the OpenSSH escape sequence ~., and it tells your local SSH client to drop the connection immediately, even if the remote host is not responding.

The order matters. The tilde is only recognised at the start of a line, so press Enter first to get to a fresh line. Then type ~ and . — you will not see them echoed, and the connection closes at once.

user@server:~# Connection to 192.0.2.10 closed.

This works because the escape is handled by the client on your own machine, not by the remote server. Your keystrokes never need to reach the frozen host. The SSH process exits, and your local terminal is back.

Do not close the whole terminal firstClosing the window kills the client too, but it also kills any other tabs or panes in that window and leaves you guessing whether the session ended cleanly. Try Enter, ~, . first — it takes two seconds.

Why does the ~. escape sometimes not work?

The escape sequence fails most often for one of three reasons: the tilde was not at the start of a line, no terminal was allocated, or your keyboard layout swallows the tilde. Each has a simple fix.

  • You were mid-line. The escape character is only recognised immediately after a newline. Press Enter first, then ~..
  • You connected with ssh -T. The -T flag disables pseudo-terminal allocation, and without a terminal the escape sequences do not work. Reconnect without -T if you need them.
  • Your keyboard layout uses a dead-key tilde. On US-International and several European layouts, ~ waits for the next keystroke before it appears. If ~. seems to do nothing, type a single ~ at a normal prompt and check that it appears.
  • You are inside a nested session. If you SSHed from one server to another, the escape is caught by the first client. Press ~~. — the doubled tilde sends one tilde through to the inner session, then . closes it.

You can list every escape your client supports by typing ~? at the start of a line. On OpenSSH it prints the supported sequences, including ~. to terminate, ~# to list forwarded connections, ~C to open a command line, and ~~ to send a literal tilde.

What happens to your programs when you exit SSH?

When the remote shell exits, its child processes receive a SIGHUP signal and are killed by default. That includes a long download, a build, or a script you started in the foreground — closing the session stops them.

If you want a job to survive after you log out, start it in a way that detaches it from the terminal:

  • nohup: run nohup ./script.sh & so the process ignores SIGHUP and keeps running after you exit.
  • disown: start a job normally, press Ctrl+Z to suspend it, then run bg and disown to detach it from the shell.
  • tmux or screen: start a session with tmux new -s work, run your commands inside it, then detach with Ctrl+B then D. Reattach later with tmux attach -t work — even from a new SSH connection.
  • systemd service: for anything that should always run, define it as a service on the server instead of tying it to your login.

For day-to-day server work, tmux is the most useful option. It also protects you from frozen sessions: if the connection drops, your work is still there when you reconnect.

Exit SSH: what survives, and what does notPlain exitShell exits, SIGHUP is sent,foreground jobs are killed.Downloads, builds and scripts stop.Work is lostInside tmux or screenDetach, then exit. The sessionkeeps running on the server.Reattach with tmux attach.Work survivesUse nohup or disown for a single long job; use tmux for an ongoing workspace.
Exiting SSH kills foreground jobs unless they are detached with nohup, disown, tmux or screen. Illustration by Cysoro.

How do I exit SSH on Windows and macOS?

The commands are the same on every platform, because they run in the remote shell, not on your local machine. Type exit, use logout, or press Ctrl+D — whichever client you use.

On macOS, use Terminal or iTerm2 and the same commands. The ~. escape works in the built-in OpenSSH client exactly as it does on Linux.

On Windows, Windows Terminal and PowerShell include OpenSSH, so exit and ~. both work. In PuTTY, typing exit closes the session and the window; closing the PuTTY window directly also ends the connection. If the OpenSSH client itself is stuck and the escape does not work, open Task Manager with Ctrl+Shift+Esc, find the ssh.exe process, and end it — that kills only that session.

If you have several SSH sessions open at once, find the right process before killing anything. On Linux or macOS, run ps aux | grep '[s]sh.*hostname' to see which process is connected to which host, then kill only that process ID.

How do I stop SSH sessions from freezing?

Frozen sessions are usually caused by a dead network path, a laptop going to sleep, or a long idle period with no traffic. A few settings make them rare — and harmless when they happen.

  • Keep the connection alive: add ServerAliveInterval 60 and ServerAliveCountMax 3 to your ~/.ssh/config. The client sends a small message every minute, so a dead connection is detected quickly instead of hanging forever.
  • Use tmux or screen: if the connection drops, your work stays on the server and you reattach in seconds.
  • Consider mosh: the mobile shell reconnects automatically after network changes and keeps your session alive across Wi-Fi switches and sleep.
  • Do not press Ctrl+S by accident: in a terminal, Ctrl+S pauses output (flow control) and the session looks frozen. Press Ctrl+Q to resume it.
  • Close idle sessions yourself: do not leave sessions open for days. Exit when you are done, and you will not come back to a dead one.

For a fuller picture of keeping remote access safe, see our guide to securing your Wi-Fi — most home SSH freezes start with an unreliable wireless connection.

LinuxConfig's guide to disconnecting from an SSH session covers the same methods, including the ~. escape for a hung connection.

Atera's guide to exiting SSH on Windows, Mac and Linux adds the Windows-specific steps, including ending the client process in Task Manager.

What mistakes do people make when exiting SSH?

Most SSH exit problems come from a small set of habits. Avoid these and the session will behave the way you expect.

  • Using Ctrl+C to exit. It interrupts the current program, not the connection. You stay logged in and wonder why nothing changed.
  • Closing the laptop lid mid-command. The network drops, the session freezes, and the next time you open the lid you have a dead terminal. Exit first, or use tmux.
  • Typing ~. in the middle of a line. The tilde is sent to the remote shell as ordinary input. Press Enter first.
  • Running exit in a subshell and thinking you logged out. If you started a second shell inside the session, exit only leaves that inner shell. Check your prompt — if it still shows the remote host, type exit again.
  • Leaving long jobs in the foreground. They die with the session. Use nohup, disown or tmux before you exit.
  • Killing the wrong SSH process. With several sessions open, killing by guess can drop the wrong one. Check the host with ps first.

The bottom line

For a normal session, type exit — or press Ctrl+D for speed. For a frozen one, press Enter, then ~., and the client drops the connection for you.

Make the habit stick: exit when you are done, and run anything long-lived inside tmux so a dropped connection never costs you work. If you manage servers from home, check your connection first with our free what-is-my-IP tool to confirm which network you are connecting from.

For a quick refresher on the commands in this guide, see our small business cybersecurity checklist, which covers safe remote access alongside backups and updates.

Frequently asked questions

How do I exit an SSH session in Linux?

Type exit and press Enter, or press Ctrl+D on an empty prompt. Both close the remote shell, which ends the SSH connection and returns you to your local prompt.

What is the shortcut to exit a frozen SSH session?

Press Enter, then tilde (~), then a full stop (.). This is the OpenSSH escape sequence ~. and it closes the connection from the client side, even when the remote host is not responding.

Does Ctrl+C exit SSH?

No. Ctrl+C interrupts the program running in the remote shell, but it does not close the SSH connection itself. Use exit, Ctrl+D, or ~. instead.

Why does ~. sometimes not work?

The tilde is only recognised at the start of a line, so press Enter first. It also needs a terminal session, so it does not work if you connected with ssh -T, which disables the pseudo-terminal.

How do I exit SSH on Windows?

In Windows Terminal, PowerShell or PuTTY the same commands work: type exit in the remote shell, or use ~. for a frozen OpenSSH session. In PuTTY you can also close the window, and in Task Manager you can end the ssh.exe process.

Will my programs keep running after I exit SSH?

No, by default. When the shell exits, its child processes receive a SIGHUP signal and are killed. Start long jobs with nohup, disown them, or run them inside tmux or screen if you want them to survive.

How do I exit SSH without closing the terminal?

Type exit or press Ctrl+D. The SSH connection closes and your local shell prompt returns in the same terminal window, ready for your next command.

What does Connection to host closed mean?

It is the normal message OpenSSH prints after the remote shell exits or the connection drops. If you typed exit yourself, it means the session closed cleanly and there is nothing to fix.

Sources

  1. LinuxConfig — Disconnect SSH Session on Linux: Exit, Logout, and More
  2. Atera — How to Exit SSH on Windows, Mac, and Linux
  3. Akamai — How to Connect to a Remote Server Over SSH on Linux
  4. DEV Community — SSH Session Frozen? How to Exit and Fix It (2026)
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against LinuxConfig and Atera SSH exit guides, Akamai's SSH guide and the OpenSSH escape-sequence documentation described in the DEV Community guide.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free