Ubuntu Linux shutdown the X server

by admin on July 31, 2006 · 17 comments

in Linux, News, Tips

Recently someone asked me a question - "How do I shutdown the X server, so that I have a command line prompt on the console?"

Well answer is very simple use script located at /etc/init.d/ directory. If you are using KDE desktop type the command (make sure you save all the work as following command does not ask confirmation):

sudo /etc/init.d/kdm stop

Within few seconds you should be dropped to a command line prompt on the console. To start GUI type command:

sudo /etc/init.d/kdm start

If you are using GNOME:

sudo /etc/init.d/gdm stop

Again to start GNOME desktop:

sudo /etc/init.d/gdm start

Another way - You can change the current runlevel

From a command line, you can use the init command to go immediately into runlevel 1, which is also known as single user text mode. Open terminal and type the following command:

sudo init 1

Again get back to GUI with init 2 command:

sudo init 2

When you type init 1 command your session will then begin to shut down and bring you into single user text mode. When you type init 2 command your session will then begin to shut down and bring you into GUI mode :)

Pretty easy ahh?

So what are GDM and KDM?

  • GDM (the GNOME Display Manager) provides an alternate display manager for the X Window System.
  • KDM (the KDE Display Manger) provides an alternate display manager for the X Window System.
  • In short, both of them are a graphical login interface for computers using Linux or Unix-like operating systems.

{ 17 comments… read them below or add one }

1 Alberto Milone August 1, 2006 at 8:37 am

You can also type:

sudo /etc/init.d/gdm restart


sudo /etc/init.d/kdm restart

2 vivek August 1, 2006 at 4:14 pm


Well, restart argument will restart the X server. My friends want to shutdown X and go to command line prompt on the console and that is what stop does.

3 T 709 August 10, 2006 at 8:49 am

Ubunto ships with a generic video driver for NVIDIA graphic cards (nv). Recent NVIDIA cards should use the newer nvidia kernel module. To achieve this, install nvidia-glx package first. Then change settings in section Device of your recent X11 configuration in /etc/X11/xorg.conf.

Section "Device"
Identifier "Graphics Card Identifier String *DO NOT CHANGE*"
Driver "nvidia"

Since Graphics Card Identifier String is referenced by onother section, you should not edit this! Only change the module name from nv to nvidia.

Then restart the X-server. Here we are again.

P.S. Resolution of the monitor can be added in the section Screen, subsection Display of xorg.conf. See man xorg.conf for details.

4 bill kress May 28, 2007 at 5:29 am

This is driving me nuts. Why did ubuntu mess with runlevels???

On every other system I’ve ever used, runlevel 1 was single user, 3 was multi-user and 5 was GUI.

Now it’s like there is only 1 and 5. I’ve never figured out a way to get into multi-user console mode.

I tried your suggestion:

bill@bill-laptop-LT:~/scripts$ sudo /etc/init.d/gdm stop
* Stopping GNOME Display Manager… [ OK ]

The reason I could paste that is because it’s still there and I’m still running, absolutely nothing happened.

This is an extremely annoying flaw in an otherwise pretty good system, but whoever decided it would be just so neat to mess with the runlevels should have svn commit rights revoked for life.

5 vivek May 28, 2007 at 3:56 pm


try init 3 command:
sudo telinit 3

You can fix this problem by editing /etc/event.d/rc-default file
Goto /etc/rc3.d and remove gdm entry
sudo rm *gdm*
Open vi /etc/event.d/rc-default
sudo vi /etc/event.d/rc-default

Find all lines read as – telinit 2 and replace with telinit 3
telinit 3

Close and save the file. Reboot system.

6 bill kress June 1, 2007 at 8:44 am

Thank you, that feels like a huge weight off my shoulders :)

It worked and I think I understand that the rcn.d system isn’t as scary as I thought.

One correction, I think you meant for me to remove the gdm entry from rc2.d?

What was the telinit change? Does that mean default to runlevel 3 instead of 2? If so, I noticed some differences in other runlevels (4&5), are these levels just unused?

Thanks again,


7 galdir September 5, 2007 at 4:52 pm

maybe these dificulties are because ubuntu is using upstart… Im learning somethings about that

8 sdshields October 17, 2008 at 8:37 pm

Using Ubuntu 8.04, when I type sudo /etc/init.d/kdm stop, it doesn’t drop to a command prompt. It drops to some text on the screen, but the prompt never shows. cntr-alt-del stops gnome and restarts the PC.

9 manu November 6, 2008 at 11:02 am

I might be late in replying but sdshields when you get the text on the screen you need to press alt + f1 or any other function key to go to a console. Then you can login from there.

10 Arun February 13, 2009 at 11:59 am

Ubuntu 8.10, when you are Grub loader menu, you can choose to run the Ubuntu in diagnostic Mode.
So the X server is not started.
You directly land at the root,
$ pwd
$ /root
$cd /
$cd —> go the directory where you have stored the NVIDIA*.run file
$sh NVIDIA*.run

Now you should be able to see the NVIDIA setup … follow instructions and it is done :)

I got strange problem after I installed the NVIDIA driver. When I booted into Ubuntu … the NVIDIA logo came … that was fine … I entered my user/pass at gui interface …
But then my screen suddenly turned BLACK … No Display …
Ctrl+Alt+F7 bought back the GUI display … I am afraid I have to do it every time … Any isead why it gave me Blank Screen !

– Arun

11 sunny dhabhai July 2, 2009 at 1:46 pm

giving ‘gdm stop’ sometimes dont work since X server still running
just do like this
pass ‘gdm stop’ in grapical mode a blue window saying X is running at display :0 whatever; dont press yes or knw let it be press
>login root
now to stop X server delete running process pic localted at :
rm /tmp/.X0 (xserver is at zero ,you can find it at /tmp/.X then tab to find whrer display running
after deleting this file you are done !!

cd /tmp ( contain running pids of all process running )
rm .X press tab its like .X0 in my box
delete it

12 Luc November 14, 2009 at 2:19 am

thank you very much:
sudo /etc/init.d/gdm stop
I can stop X but can not login to my system any more. (I am certain that uname and passwd is correct but still fail). What might be the cause?

13 Roger November 18, 2009 at 6:34 pm

I also can’t stop Gnome typing
sudo /etc/init.d/gdm stop
The complete system then hangs for any reason.
Come on, there are many ways to get it done, e.g.
sudo gedit /etc/init.d/gdm
Search for “start)”. Change it to “dostart)”. Save the file.
shutdown -r now
Bingo! Do your job and start x with
sudo /etc/init.d/gdm dostart
or simply try startx. Should work.
sudo gedit /etc/init.d/gdm
Search for “dostart)”. Change it back to “start)”. Save.
Besides its not a bad idea to copy gdm to your desktop before this operation. Do it as root, so type sudo cp … So you can copy it back if something bad has happened.

14 d9ping July 7, 2010 at 1:55 pm

It doesn’t work anymore in ubuntu 10.04.

$ sudo /etc/init.d/gdm stop
sudo: /etc/init.d/gdm: command not found

15 Anonymous August 6, 2010 at 2:37 am

In ubuntu 10.04 press CTRL+ALT+F1 and type (without the quotes) “sudo service gdm stop”
to start it type (again without the quotes) “sudo service gdm start” and after srart if youre not automatically kicked back into X, just press CTRL+ALT+F7

16 Bob February 11, 2011 at 12:48 am

I just want to shut down x windows???? Why do I have to edit a bunch of files and potentially corrupt my installation????

17 dutchy March 17, 2011 at 2:17 pm

With Ubuntu 10.04+ they changed the system to use service menus, so this is the new format to accomplish the same thing:

$sudo service gdm stop

Leave a Comment

Previous post:

Next post: