336

How can I restart X Window Server from the command line?

I'd really like to be able to restart my GUI without having to do a full system reboot.

antivirtel
  • 3,645

7 Answers7

353

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 (lightdm till 17.04, gdm3 after, sddm in Kubuntu, etc.). You can replace display-manager with lightdm, gdm3, 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:

cat /etc/X11/default-display-manager

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
    
PJ Brunet
  • 1,383
  • 1
  • 8
  • 11
txwikinger
  • 28,462
  • 4
    This probably changed for Unity. My system cannot find gdm. – Steven Roose Sep 16 '12 at 12:25
  • 1
    AFAIK Unity uses lightdm – txwikinger Mar 25 '14 at 23:51
  • 2
    It seem to close all the applications and documents immediately without saving (unlike regular restart), what's the difference between this and sudo reboot? – Amir Uval Feb 01 '15 at 16:23
  • 2
    @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 – d.k Jun 16 '16 at 06:43
  • 2
    I get restart: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused. – William Oct 10 '16 at 18:16
  • 1
    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). – Jon Spencer Mar 19 '17 at 20:21
  • cat /etc/X11/default-display-manager is the way to start... good job! – Cipi Aug 14 '17 at 13:20
  • 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? – Daniel Smolkin Sep 04 '17 at 19:47
  • 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 – Daniel Smolkin Sep 04 '17 at 20:03
  • 1
    This killed an ongoing download as closed the browser. Ubuntu 16.04 – juliangonzalez Dec 08 '17 at 18:13
  • 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. – Giorgi Gvimradze Jun 11 '19 at 13:56
  • nice on, first command worked for me. Monitors got black, nothing happend several seconds. after half a minute the start screen with default ubuntu 16.04 rised back agin =)! – Cutton Eye Nov 20 '19 at 09:28
  • 18.04 sudo systemctl restart display-manager from ssh asked me if I am the displayed user, entered the password but it started asking the same question over and over again. Meanwhile, also from shh top displays graphical programs like firefox and thunderbird are running. sudo pkill Xdid the thing. Now all graphical programs were closed – dstonek Jul 12 '20 at 00:20
  • @juliangonzalez this is totally expected. It basically logs you out instantly. – xeruf Aug 05 '20 at 13:40
  • Thanks a lot. KDE plasma once hung & I was unable to do anything (not even use Ctrl+Alt+Fn to switch to a TTY). I SSHed into it, ran this command & it helped. – Puspam Apr 13 '22 at 18:23
  • This works as of Kubuntu 22.04, when X11 has crashed for some reason while switching accounts. TYSM! Really looking forward to Wayland support for Nvidia . – TheLabCat Jan 07 '23 at 20:27
41

For 11.04 and earlier:

sudo service gdm restart

For 11.10 and later:

sudo service lightdm restart

jokerdino
  • 41,320
  • +1 Works nicely on the Raspberry Pi as well (in case anyone is curious, that's what got me here :) – Levon Aug 06 '14 at 18:03
23

Found out that you can do sudo pkill X

and it seems to work for me!

gontadu
  • 832
12

You can try pressing Ctrl+Alt+Backspace to restart X.

  • 8
    This is deactivated by default in 10.04 and will therefore normally not work. – Marcel Stimberg Aug 05 '10 at 18:28
  • 6
    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'. – dv3500ea Aug 05 '10 at 18:33
  • 9
    The correct shortcut is "Alt+SysRq+k", however he asked for command line. – Li Lo Aug 05 '10 at 20:44
10

Newest version of Ubuntu as of 24 Oct, 2012.

  1. Open Dash Home
  2. Search for keyboard layout
  3. Click Options
  4. Expand tab labelled "Key sequence to kill the X server"
  5. Enable it and Close.

Command Line:

sudo restart lightdm
Nathan
  • 109
9

Since ubuntu 9.04 Ctrl+Alt+Backspace is disabled, however you can now type Alt gr + Print Screen + K.

http://www.sudo-juice.com/ubuntu-11-10-restart-x-shortcut/

Kris Harper
  • 13,477
uboonto
  • 99
  • 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). – Asher Dec 22 '11 at 15:49
  • 6
    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 – Stefano Palazzo Dec 22 '11 at 17:50
1

For KDE:

sudo systemctl restart sddm.service