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.

link|improve this question

67% accept rate
feedback

5 Answers

up vote 23 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
link|improve this answer
feedback

For 11.04 and earlier:

sudo service gdm restart

For 11.10 and later:

sudo service lightdm restart

link|improve this answer
1  
as of 11.10 sudo service lightdm restart – realgt Jan 4 at 13:32
feedback

You may try pressing Ctrl+Alt+Backspace.

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

Found out that you can do sudo pkill X

and it seems to work for me!

link|improve this answer
feedback

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/

link|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
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
feedback

Your Answer

 
or
required, but never shown

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