logout Command
The logout command terminates the current login shell session, properly ending the user session and returning control to the parent process or login prompt.
Syntax
Description
The logout command is a shell built-in that terminates the current login shell session. It can only be used in login shells and provides a clean way to end a user session.
Key characteristics:
- Works only in login shells
- Executes logout scripts and cleanup
- Updates login records and logs
- Terminates all child processes
- Returns to parent shell or login prompt
Basic Usage
Simple logout
Terminates the current login shell session
Keyboard shortcut
EOF (End of File) signal that triggers logout
Check if in login shell
Verify if current shell is a login shell
Logout Process
Steps During Logout
- Signal Handling - Process logout signal
- Script Execution - Run logout scripts (~/.bash_logout)
- Process Cleanup - Terminate child processes
- Session Recording - Update login records
- Resource Cleanup - Free system resources
- Shell Termination - Exit the shell process
Logout Scripts
Example logout script for cleanup tasks
Alternative Logout Methods
Using exit Command
Basic exit
Works in both login and non-login shells
Exit with status code
Exit with specific return code
Keyboard Shortcuts
End of file (EOF)
Universal logout/exit shortcut
Interrupt signal
Other keyboard shortcuts (not for logout)
Session Management
Checking Session Status
Current user and session info
Display current session information
Login history
View login and logout history
Session Timeout
Set automatic logout timeout
Configure automatic session timeout
Remote Session Logout
SSH Session Logout
Normal SSH logout
Standard methods to end SSH sessions
Disconnect SSH session
Force disconnect SSH sessions
Screen/Tmux Sessions
Screen session logout
Manage screen session termination
Tmux session logout
Manage tmux session termination
Troubleshooting Logout Issues
Common Problems
Logout command not working
Resolve logout command issues
Hanging logout process
Handle hanging logout due to background processes
Stuck in nested shells
Exit from nested shell environments
Security Considerations
Secure Logout Practices
Clear sensitive data on logout
Secure cleanup during logout
Automatic screen lock
Automatically lock screen during logout
Audit and Logging
Log logout events
Track logout events for security auditing
Best Practices
Logout Best Practices
- Always Logout - Properly end sessions when finished
- Save Work - Save all work before logging out
- Close Applications - Exit applications cleanly
- Check Background Jobs - Ensure no important processes are running
- Secure Cleanup - Clear sensitive data during logout
- Use Timeouts - Set automatic logout for idle sessions