Shell
logout
Exit a login shell or terminate a session.
shellexitsessionlogin
Additional Notes
logout is a shell built-in that exits a login shell. When used in a login shell, it terminates the session. In a non-login shell or a subshell, logout is not valid and exit should be used instead.
It is commonly used to end SSH sessions, exit from console logins, or terminate a su - session. The command honors the shell's job control and will warn about stopped jobs before logging out.
Syntax
logout [n]
Parameters
n: Optional exit status (an integer). Defaults to the exit status of the last command executed.
Examples
logout
Exit the current login shell.
logout 1
Exit with a non-zero status, indicating an error condition.
ssh user@host
# ... work ...
logout
End an SSH session.
Practical Notes
- In a non-login shell,
logoutwill fail withnot a login shell. Useexitinstead. exitworks in both login and non-login shells and is the more universal command.- Some shells prompt about stopped background jobs before allowing logout. Use
disownorkillto handle them first. - In bash,
logoutis equivalent toexitonly when the shell is a login shell.