Hostxpeed
Login Get Started →
Getting Started

How to Exit From SSH Session

3 min read
22 views
Jun 10, 2026

Prerequisites

Before exiting an SSH session, make sure you have:

  • An active SSH connection to your VPS
  • Saved any work or running processes

💡 Properly exiting ensures your terminal is clean and no processes are left hanging.

Method 1: Using exit Command (Most Common)

In your SSH session, type:

exit

You will see:

logout
Connection to YOUR_SERVER_IP closed.

Method 2: Keyboard Shortcut (Ctrl+D)

Press:

Ctrl + D

This sends EOF (End of File) and closes the session immediately.

Method 3: Using logout Command

logout

Works the same as exit on most systems.

Method 4: Close Terminal Window

Simply close your terminal application. This will terminate the SSH session automatically.

Method 5: Kill SSH Session from Inside

kill -9 $$

This kills the current shell process (not recommended unless stuck).

Method 6: Exit from Nested Sessions

If you have multiple sessions (e.g., su to another user), you need to exit each level:

exit  # exit user session
exit  # exit root session
exit  # exit SSH session

You can see your nesting level with:

echo $SHLVL

Exit from su or sudo -i

If you switched to another user:

su username

To exit back to previous user:

exit

Exit from Screen or Tmux Session

If you're inside screen:

screen -r

To exit screen but keep session running:

Ctrl + A, then D

To kill screen session:

exit

Detach SSH Session (Keep Running)

If you want to leave processes running after disconnecting:

nohup command &

Or use screen/tmux:

screen -S mysession
# run your command
Ctrl + A, then D  # detach
exit  # exit SSH, screen session keeps running

Later reconnect:

screen -r mysession

Check if You're Still Connected

Before exiting, verify you're on the remote server:

hostname

If it shows your VPS hostname, you're on remote server.

Check logged-in users:

who

Shows all active SSH sessions.

Automatic Exit After Idle Time

To automatically disconnect idle SSH sessions, add to /etc/ssh/sshd_config:

ClientAliveInterval 300
ClientAliveCountMax 2

This disconnects after 10 minutes of inactivity (300s * 2).

Troubleshooting: Stuck SSH Session

If SSH session freezes:

  • Press Enter, then ~, then . (tilde then period)
  • Or close terminal and reopen

The escape sequence ~. (Enter, tilde, period) forces disconnect.

✅ You have successfully exited your SSH session. Your Hostxpeed VPS continues running in the background.

Was this article helpful?