Linux Command to Log Out a User: Safe Options
In this article
To log out the current user from a Linux terminal, run exit or press Ctrl+D. To end another user’s session, first identify the correct session and use loginctl terminate-session SESSION_ID on systems managed by systemd; this forcibly ends that session and can discard unsaved work.
Choose the command for the situation
“Log out” can mean closing your own shell, ending a graphical desktop session, or removing another account’s active login. These are different actions, so choose the command that matches the session you intend to close:
- Current terminal shell: use
exitorCtrl+D. - Your graphical desktop: use the desktop environment’s Log Out option, or run
gnome-session-quiton a GNOME desktop when that command is available. - Another user’s session on a systemd machine: inspect sessions with
loginctl list-sessions, then terminate the intended session withloginctl terminate-session ID. - All sessions belonging to an account: use
loginctl terminate-user USERNAMEonly when ending every session for that account is intended.
Commands and desktop behavior vary across Linux distributions and session managers. In particular, ending a terminal shell is not automatically the same as logging out of the desktop that launched it.
Logging out of your own terminal
In an interactive shell such as Bash, typing exit ends that shell. Pressing Ctrl+D sends an end-of-file signal; at an empty command prompt, shells commonly interpret it as a request to exit. If the shell was the only process in a terminal window, the window may close. If it was opened inside another shell, control returns to the previous one instead.
exit
For example, if you connect to a remote server using SSH, running exit in the remote shell normally closes that SSH login and returns you to your local terminal. If you started a nested shell or used su to become another account, it may only leave the innermost shell. Run exit again if you intend to close the outer session too.
Some shells warn that there are stopped jobs when you try to exit. Review them with jobs; a job suspended with a keystroke such as Ctrl+Z may still be running. You can resume it with fg, or stop it deliberately before closing the shell. Do not assume that closing a terminal safely saves or stops every program.
Logging out of a graphical desktop
For a desktop session, the most reliable general method is the desktop’s own Log Out command. It lets the session manager close applications and may give you a chance to save open documents. GNOME installations may provide gnome-session-quit, but options and availability depend on the GNOME version and distribution. Check gnome-session-quit --help before using flags; a command-line logout can end the session without the same confirmation flow as the desktop menu.
Closing a terminal window normally closes only the terminal and its shell, not the full desktop. Likewise, logging out of a text console does not necessarily end a separate graphical session owned by the same user. If you need to leave a shared computer, confirm that the desktop has returned to its login screen rather than merely closing one application.
Ending another user’s session with loginctl
On a systemd-based system, loginctl manages sessions tracked by systemd-logind. Start by listing sessions:
loginctl list-sessions
The output includes session IDs and user information. Inspect a candidate before acting:
loginctl session-status 3
Replace 3 with the ID shown on your machine. Once you have verified the session, terminate it with:
sudo loginctl terminate-session 3
Administrative privileges are generally required to terminate another user’s session. The command targets that session; it is different from loginctl terminate-user alice, which ends all sessions for the named account. Check the local loginctl manual page because supported operations and policies can vary. On non-systemd distributions, loginctl may not be installed or may not manage the relevant session.
Termination is not a graceful request to save work. It can stop applications, close remote connections, and lose unsaved data. If possible, notify the user and ask them to log out normally. Use forced termination for a clear administrative need, such as a session that is unresponsive or an account that must no longer remain logged in.
Commands that are not the same as logging out
Several familiar commands affect processes or access without necessarily ending a complete login session:
logoutis a shell built-in intended to exit a login shell. It may report an error in a non-login shell; useexitfor the more general shell-exit command.who,w, andusersshow logged-in users or session activity. They are useful for checking, but do not log anyone out.killsends a signal to a process. Killing one terminal or desktop process may leave other processes or session components running, so it is not a dependable substitute for ending a session.sudo -u USER commandruns a command as another account; it does not create a normal interactive login that you can log out of in the usual sense.
A common misconception is that exit logs out an account everywhere. It only exits the current shell. The same user can remain logged in through another terminal, a desktop, or a separate SSH connection.
Permissions and practical safety
Before terminating someone else’s session, confirm the username and session ID rather than relying on a remembered ID, which may change after sessions start or end. On shared or production systems, consider whether the session is running a long task or holding unsaved work. If the issue is only an inactive shell, contacting the user is usually safer than terminating it.
For your own shell, save files and stop or detach any work that must continue. Programs launched in a terminal may receive a hangup signal when the shell closes, but behavior depends on how they were started and configured. If a task must persist, use an appropriate service, job scheduler, or terminal multiplexer such as tmux rather than assuming it will survive logout.
Frequently Asked Questions
What is the simplest Linux logout command?
For the current terminal shell, run exit or press Ctrl+D at an empty prompt. For a graphical desktop, use its Log Out option.
How do I log out of SSH?
Run exit in the remote shell, or press Ctrl+D at an empty prompt. This closes that SSH shell; other connections from the same account remain open.
How do I log out another user in Linux?
On a systemd system, run loginctl list-sessions, verify the intended session with loginctl session-status ID, then use sudo loginctl terminate-session ID. This ends the session rather than asking it to save work.
Does exit shut down Linux?
No. It exits the current shell. The terminal may close if that shell was its main process, but the operating system and other user sessions keep running.
How can I log out of all sessions for one user?
On a systemd-managed machine, sudo loginctl terminate-user USERNAME ends all sessions tracked for that account. Verify the account name first, and use this only when ending every session is intended.