logout Command Cheat Sheet
The logout command terminates a login shell.
Synopsis
logout
Usage
End SSH Session
logout
End TTY Session
If you are on a physical console (Ctrl+Alt+F1).
logout
Logout vs Exit
logout: Only works in a login shell (the top-level shell obtained after login).exit: Works in any shell (subshells, scripts, login shells).
If you try logout in a subshell:
bash
logout
# Output: bash: logout: not login shell: use `exit`
Hooks (~/.bash_logout)
When you run logout, the shell looks for ~/.bash_logout.
You can put cleanup commands there:
- Clear screen (clear).
- Remove SSH agent keys.
- Print "Goodbye".
Notes
- In GUI Terminal emulators (GNOME Terminal),
logoutmight close the window or tab, depending on profile settings. - It is a shell builtin.