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:
exitYou will see:
logout
Connection to YOUR_SERVER_IP closed.Method 2: Keyboard Shortcut (Ctrl+D)
Press:
Ctrl + DThis sends EOF (End of File) and closes the session immediately.
Method 3: Using logout Command
logoutWorks 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 sessionYou can see your nesting level with:
echo $SHLVLExit from su or sudo -i
If you switched to another user:
su usernameTo exit back to previous user:
exitExit from Screen or Tmux Session
If you're inside screen:
screen -rTo exit screen but keep session running:
Ctrl + A, then DTo kill screen session:
exitDetach 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 runningLater reconnect:
screen -r mysessionCheck if You're Still Connected
Before exiting, verify you're on the remote server:
hostnameIf it shows your VPS hostname, you're on remote server.
Check logged-in users:
whoShows all active SSH sessions.
Automatic Exit After Idle Time
To automatically disconnect idle SSH sessions, add to /etc/ssh/sshd_config:
ClientAliveInterval 300
ClientAliveCountMax 2This 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.