How to restart X Window Server from command line?
NOTE: This will forcefully quit all graphical programs, you'll lose any unsaved work, and you'll be logged out. Non-graphical programs will not be affected.
TL;DR: on systems with systemd (Ubuntu 15.04 and newer)
sudo systemctl restart display-manager
This will restart the appropriate display manager service (
sddmin Kubuntu, etc.). You can replace
sddm, etc. if needed, but this should be enough.
For other Ubuntu versions, first find which display manager your ubuntu is having with following command:
Than depending on what display manager, you can use one of the following commands:
Default Ubuntu (with LightDM)
sudo systemctl restart lightdm
Gnome (with GDM)
sudo systemctl restart gdm
KDE (with KDM)
sudo systemctl restart kdm
Note: From 12.10 to 15.04, Kubuntu also uses LightDM.
For MDM (e.g. for Mint Cinnamon)
sudo systemctl restart mdm
It seem to close all the applications and documents immediately without saving (unlike regular restart), what's the difference between this and sudo reboot?
@uval, `sudo reboot` reboots all your system, that is the computer, while this restarts only the Xorg server, so that other programs, which do not require a graphical interface, for instance a web server, can continue to work. As well as all mounter file systems (like encrypted ones), all connections to remote hosts etc. do persists in the case of this instead of the `reboot` command
I get restart: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused.
This (sudo systemctl restart sddm.service) worked great for Kubuntu 16.04 LTS. It does kill all running apps and requires reauthentication. My problem was that while I could select a window, I could not move any windows. Now it's all happy (and so am I).
Running "sudo systemctl restart lightdm.service" seems to have broken xorg or lightdm or something for me. Now when I restart my laptop I just get a black screen with a blinking cursor. What do I do?
Referring to my earlier comment: the solution seemed to be to restart lightdm.service again from a TTY. However, then I got stuck in a login loop, just like in this question (https://askubuntu.com/questions/223501/ubuntu-gets-stuck-in-a-login-loop). The accepted answer to that question solved my problems
The first command run from terminal did its job, but I couldn't get logged in. Looks like it made me logged out for ever.
You can try pressing Ctrl+Alt+Backspace to restart X.
This is deactivated by default in 10.04 and will therefore normally not work.
It can be reactivated though, by going to System -> Preferences -> Keyboard, clicking the 'Options...' button in the 'Layouts' tab and enabling 'Key sequence to kill the x server'.
Since ubuntu 9.04 Ctrl+Alt+Backspace is disabled, however you can now type Alt gr + Print Screen + K.
Alt+PrtScr/SysReq+k logged me out pdq and my programs were killed or terminated. Is this the desired behaviour expected when restarting X-server? I have 11.10 and sudo restart lightdm took me into text mode and seemed to stay there shutting down a bunch of daemons then stopping. I had to reboot manually fortunately the off button does it gracefully (sometimes).
SysRq+k kills all running processes and child-processes on the current terminal (i.e. the one running your X-server). Using it may cause the system to lose data! See: http://askubuntu.com/questions/14155/what-to-do-when-ctrl-c-wont-kill-running-job/14158#14158