The Linux logout command lets you cleanly end your current session, freeing up system resources and removing access for other users. You’ll need no special tools—just your terminal or graphical session—but ensure you’re not in critical files or processes before logging out.
What You'll Need
- A running Linux system (desktop, server, or embedded).
- Your current user session open (via terminal, GUI desktop, or SSH).
- If running GUI apps, be mindful of unsaved work (see "Tips" for saving strategies).
- No additional software needed—built-in commands suffice.
Step-by-Step
-
In terminal: Open your command-line interface (Ctrl+Alt+T on many desktops). Use one of these commands to exit:
logout– Immediate logout (does not save desktop session).exit– Same as logout (common shortcut).pkill -u $USER– Forcefully terminates all user processes (use with caution).
- GUI desktop: Click the top-left menu (application launcher) > Quit or Exit (e.g., GNOME menu > Quit > Exit). This saves desktop settings (like window layouts) before logging out.
-
SSH session: On remote servers, type
exitorlogoutin the terminal. Logout does not close the SSH connection—useexitorcontrol-Dto fully disconnect. -
Systemd-based systems: For services managed by systemd (most modern Linux), log out via any standard method. Logout terminates the user session but leaves systemd services running unless you use
systemctl isolate default(requires sudo).
Common Mistakes
-
Using
killorpkillincorrectly: These forcefully terminate processes. Only usepkill -u $USERif absolutely necessary (e.g., stuck sessions), but it may leave orphaned processes. Avoid on shared servers. - Ignoring unsaved work: Logout does not save GUI desktop sessions by default. Use
exitor GUI menus to save before logging out, or back up files manually. -
Confusing logout with reboot: Logout only ends your session; reboot requires
sudo rebootorsudo shutdown -r now. Typingrebootby mistake will halt everything. -
Overlooking sudo privileges: If you’re logged in as root,
logoutworks, but sudo may prompt for a password afterward if services require it.
Tips
-
Save before logging out: For GUI apps, use
Alt+F2> typer> confirm to restart the desktop environment (saves session). On TTYs, useexitwith a backup plan. -
Check for locked files: If you’re unsure if processes are running, run
ps -u $USERto list user processes. Close only what you need (e.g.,killa single process). -
Use
loginctlfor systemd: List sessions withloginctl list-sessionsto check active users. Kill a session withloginctl terminate-session(replacewith the session ID from the list). -
SSH sessions: If you’re unsure if you’re fully disconnected, run
ssh -vto debug reconnection attempts. -
Automatic logout: To set a default timeout (e.g., 5 minutes), edit
/etc/systemd/logind.conf:HandleLongevity=ignoreIdleAction=relax(Requires systemd; note: this affects all users.)
Troubleshooting
-
Logout doesn’t work:
- Check if another session is running:
whoorw. If another user is logged in, log that user out first. - Verify the command is recognized: Try
which logout. If it returns nothing, your system usesexitas the default. - Restart the session: On desktop, log in again; on TTY, press
Ctrl+Alt+F2to switch to a fresh TTY. - Check systemd status: If you’re on systemd, run
systemctl status systemd-logind. A crash may block logout.
- Check if another session is running:
-
Processes persist after logout:
- List processes:
ps -ef | grep $USER. Identify orphaned processes (e.g.,grep -v grepto exclude grep itself). - Kill processes one by one:
kill -9(replacewith the process ID). - Reset the user session:
loginctl terminate-user $USER(systemd only).
- List processes:
-
GUI session freezes on logout:
- Kill the desktop environment:
pkill gdm(GNOME),pkill kdeinit(KDE), orpkill xrdp(Remote Desktop). - Log in via TTY (Ctrl+Alt+F2) and restart the desktop.
- Kill the desktop environment:
Frequently Asked Questions
How do I log out from a TTY?
- Use
exitorlogoutin the terminal. If you’re in an SSH session,exitwill fully disconnect.
Can I log out without closing all my applications?
- For GUI sessions, use
Alt+F2>rto restart the desktop (saves session). - For TTYs, save files manually or use
exitwith a backup plan.
What if my logout command doesn’t work?
- Check for another session: Run
whoorw. If another user is logged in, log that out first. - Try logging in via a different TTY (Ctrl+Alt+F2) and using
exitthere.
How do I log out remotely on a server?
- SSH into the server and type
exitorlogout. This closes the SSH session. - If you need to fully reboot, use
sudo reboot.
Will logging out affect systemd services?
- Logout ends the user session but leaves systemd services running unless you use
systemctl isolate default. - To stop a service during logout, add
--systemto your logout command (e.g.,sudo systemctl isolate default --force).
How can I force a logout if I’m stuck?
- Switch to another TTY (Ctrl+Alt+F2), become root with
sudo su, and runloginctl terminate-user $USER(systemd). - Or kill all user processes with
pkill -u $USER(use with caution).
Remember: Always verify your session before forcefully closing it, especially on shared systems.