Need to close Xorg on Linux? The safest method depends on what you mean by “close”: you may want to log out of your desktop, stop the graphical display manager, or end a standalone X session. In most cases, you should close your desktop session rather than kill the Xorg process directly. This lets applications save their work and allows Linux to shut down the graphical session cleanly. The steps below explain how to close Xorg from a desktop, a terminal, or a remote connection, and how to avoid common problems.
What Does It Mean to Close Xorg?
Xorg, also called the X server or X11 server, provides the graphical display and input layer used by many Linux desktop environments. It is not usually the desktop itself. GNOME, KDE Plasma, Xfce, and other environments run alongside Xorg and manage the windows, panels, and applications you see.
Because these components work together, closing Xorg directly can end your entire graphical session. Unsaved documents may be lost, and a display manager may immediately start a new login screen. The best approach is to use your desktop’s normal logout or shutdown option whenever possible.
Before choosing a method, consider your goal:
- Return to the login screen: Log out of your desktop session.
- Turn off the graphical login screen: Stop the display manager.
-
Close a manually started X session: Exit the window manager or application started by
startx. - End a frozen session: Switch to a text console and terminate the specific session or process.
Close Xorg by Logging Out of Your Desktop
For most Linux users, logging out is the simplest and safest way to close Xorg. Open your desktop’s system menu, select Log Out or Sign Out, and confirm if prompted. Your desktop environment will close applications, end the session, and shut down its Xorg server when appropriate.
The exact menu location varies. In GNOME, open the system menu in the top-right corner and choose the power or session options. In KDE Plasma, open the application launcher or system menu and select Leave, then Log Out. Xfce users can usually find Log Out in the applications menu or desktop context menu.
Logging out is different from locking the screen. Locking keeps your session and Xorg running in the background. Logging out ends the session. If you only need to protect your screen while stepping away, use the lock option instead.
Save open files before logging out. Some applications display a prompt for unsaved work, but not every program can restore its state after the session ends.
Close a Manually Started Xorg Session
If you started Xorg yourself with startx, the session often ends when its main client or window manager exits. For example, close the window manager from its menu, or use its documented exit command. If your .xinitrc file starts a terminal or another application, closing that program may end the session, depending on how the file is configured.
When the session ends normally, startx and xinit clean up the X server they started. This is preferable to terminating Xorg separately because it follows the session’s intended shutdown sequence.
If you launched a single graphical program with xinit, close that program as you normally would. If the X session remains open, check what your startup script launches. A window manager that is still running can keep the session active even after the visible application closes.
Stop the Display Manager from a Terminal
A display manager provides the graphical login screen and starts desktop sessions. Common examples include GDM for GNOME, SDDM for KDE Plasma, and LightDM for several other desktop environments. Stopping the display manager usually closes graphical sessions on that system and may switch the computer to a text console.
To stop it, open a terminal and run:
sudo systemctl stop display-manager.service
This command may log out other people using the computer, so do not run it on a shared machine without warning them. It may also make the graphical login screen disappear. On some distributions, the service alias may not be available. Find the active display manager with:
systemctl status display-manager
You can also check common service names with commands such as:
-
systemctl status gdmorsystemctl status gdm3 systemctl status sddmsystemctl status lightdm
If necessary, stop the service that is actually installed, for example sudo systemctl stop gdm or sudo systemctl stop sddm. Service names vary by distribution, so check the status before choosing one.
To restore the graphical login screen, start the relevant service again. For example, use sudo systemctl start display-manager.service, or start the specific service you stopped. If the service does not restart, check its status and system logs rather than repeatedly issuing commands.
Close a Session from a Text Console
If the desktop is frozen or you cannot open a terminal window, switch to a virtual console. Press Ctrl + Alt + a function key such as F3 or F4. On some laptops, you may also need to hold Fn. The graphical desktop is often on another function key, commonly F1 or F2, depending on the distribution.
Sign in at the text prompt. To see active login sessions, run:
loginctl list-sessions
Identify the session belonging to your user, then end that specific session with:
sudo loginctl terminate-session SESSION_ID
Replace SESSION_ID with the actual session identifier shown in the list. Terminating a session closes its processes, so unsaved work may be lost. Avoid using a command that terminates every session unless you intend to log out all users.
Afterward, return to the graphical session with the appropriate function key if it is still running. If you stopped the display manager, use the start command for that service to bring back the login screen.
Terminate the Xorg Process as a Last Resort
Directly terminating Xorg is usually unnecessary. Use this option only when normal logout and session-management commands are unavailable or have failed. Ending the Xorg process abruptly can close every application in the session without giving programs a chance to save data.
First, inspect the running processes:
pgrep -a Xorg
Some systems use a different X server process name, so you may also see X in process listings. If several graphical sessions or users are active, there may be more than one relevant process. Confirm which process belongs to the session you intend to close before taking action.
If you have verified the correct process ID, send it a normal termination signal:
sudo kill -TERM PID
Replace PID with the process ID you identified. Do not copy a sample number or guess. Avoid broad commands such as sudo killall Xorg on a multi-user computer, because they can terminate more than your own session. Also avoid using kill -9 as a first response. It prevents normal cleanup and should be reserved for a process that will not stop after safer options have been tried.
If Xorg restarts immediately, the display manager is probably configured to launch a new graphical session. Stop the display manager using the service instructions above if your goal is to keep the system in text mode.
Close Xorg over SSH or a Remote Connection
Be careful when managing a graphical session remotely. If you connect with SSH and use X11 forwarding, graphical applications running on the remote machine generally send their display to an X server on your local computer. Closing the local X server is not the same as closing a remote Xorg desktop session.
For X11 forwarding, close the forwarded application and then end the SSH connection when you are finished. If you need to log out a full desktop session on the remote computer, use loginctl list-sessions to identify the correct session and terminate only that session. Do not stop the remote display manager unless you intend to affect other users or the machine’s graphical login.
Before stopping a display manager over SSH, confirm that you can reconnect through SSH afterward. Stopping the graphical interface should not normally stop the SSH service, but system configuration varies. If the computer is remote and has no alternate access method, an incorrect command could leave you unable to manage it conveniently.
Common Problems When Closing Xorg
- The login screen returns immediately: This is expected when the display manager remains active. Stop its service if you want to keep the computer in text mode.
- The screen turns black: You may have stopped the display manager or switched to a different virtual console. Try switching consoles, or start the display manager again from a text login.
- The Xorg process will not stop: Check whether you selected the correct process and whether you have permission to end it. Try a normal termination signal before considering stronger measures.
- Another user’s desktop closes: The command may have targeted a shared display manager or the wrong session. Use session IDs and verify the account before terminating a session.
- You are using Wayland: Wayland is a different display system. A desktop may use Wayland even though Xorg-related compatibility components are installed. Logging out through the desktop menu remains the recommended approach.
How to Choose the Right Method
If you simply want to leave your desktop, log out normally. If you started X with startx, exit the window manager or main application. If the screen is frozen, use a virtual console and identify the correct session with loginctl. Stop the display manager only when you want to shut down the graphical login service, and terminate the Xorg process directly only as a last resort.
These distinctions matter because “close Xorg” can mean ending one user’s desktop, switching Linux into text mode, or stopping the graphical login system for everyone. Choosing the narrowest action helps protect other users’ work and reduces the risk of losing unsaved files.
Conclusion
The safest way to close Xorg is usually to log out of your Linux desktop using its normal menu. For a manually started X session, close the window manager or application that keeps it running. Use loginctl from a text console to end a specific stuck session, and stop the display manager only when you intend to disable the graphical login. Directly killing Xorg can be disruptive, so verify the process and use it only when safer methods do not work. With the right method, you can close an Xorg session cleanly while minimizing disruption and protecting your work.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.