Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I restart x-server from the command line?

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

share|improve this question

7 Answers

up vote 47 down vote accepted

Depending if you use lightdm (ubuntu 11.10 and later), gdm (gnome) or kdm (KDE) you can use one of the following commands:

sudo restart lightdm  

,

sudo restart gdm

or

sudo restart kdm

UPDATE: From 12.10, Kubuntu also uses lightdm

share|improve this answer
1  
This probably changed for Unity. My system cannot find gdm. – Steven Roose Sep 16 '12 at 12:25

For 11.04 and earlier:

sudo service gdm restart

For 11.10 and later:

sudo service lightdm restart

share|improve this answer

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

share|improve this answer
5  
This is deactivated by default in 10.04 and will therefore normally not work. – Marcel Stimberg Aug 5 '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 5 '10 at 18:33
3  
The correct shortcut is "Alt+SysRq+k", however he asked for command line. – Li Lo Aug 5 '10 at 20:44

Found out that you can do sudo pkill X

and it seems to work for me!

share|improve this answer

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/

share|improve this answer
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
1  
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: askubuntu.com/questions/14155/… – Stefano Palazzo Dec 22 '11 at 17:50

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
share|improve this answer

This blog article describes the best way to bind the X server to a key command for those who are looking for that. Not exactly what you asked for, but it provides the same functionality unless you are ssh'ed into another computer. It also works in 12.04 fortunately.

share|improve this answer
3  
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Peachy Sep 15 '12 at 11:16

protected by Community Mar 4 at 3:43

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.