Wednesday, July 1, 2009

Disable GUI in CentOS/RHEL

The default installation of CentOS includes the GNOME GUI desktop environment. During installation you can choose to not install this, but lets just say that you wanted to install the GUI along with the rest of the system. Now you have a CentOS server configured the way you want it and the GUI really doesn't need to be running most of the time. A GUI uses system resources that could be going somewhere else and also makes the system more vulnerable to attack since there are more processes running.

If you want to prevent the GUI from loading but want the rest of the system to load as usual, you need to make a change to "/etc/inittab". Make a backup copy of the file first:
cp /etc/inittab /etc/inittab.orig
Now assume superuser priviledges and open "/etc/inittab". Locate the line that looks like this:
This is the line that defines the default runlevel. Runlevel 5 is multiuser mode with the GUI. Change this to read:
The only change is the the 5 is now a 3. This corresponds to multiuser mode without the GUI. Now just restart and the system will boot to runlevel 3 instead of 5. To check the current runlevel, run this command:
Once you have done this and you decide you want to use the GUI, log in and run this command to start it:
This, however, will only last until you reboot next. After that the GUI will not load. To set the machine so that the GUI does load automatically, just restore your backup or "/etc/inittab" or edit the line you changed earlier and change the number back to a 5.


  1. Very useful post thanks. The CentOS 6.2 install doesn't seem to give you an option to do a minimal server install so I had to do this to stop the GUI on boot

  2. Another thing you can do is press ctrl+alt+f2 to go into cli only mode and press ctrl+alt+f5 to go into gui mode

  3. i am confused, :(
    i did install centos 6.2 GUI, but please tell me how to remove gui or how to boot the server without GUI Appreciate your effort.

  4. read what was posted. You just need to change one line on one file.
    thats it

  5. The above post is helpful ...but it changes the run level to 3 . What if I want to disable the GUI on start up on same run level i.e run level 5 ? The similar task on Fedora 21 can be done by systemctl disable lightdm (being desktop environment xfce/lxde)
    I tried to do so on redhat and i found rhel 6 is system 5 and further versions are systemd ..... if any one knows how to disable gui at startup on same runlevel plz do needful !

    1. Please google what runlevel 5 means.