Running X Applications as Root in Linux

You are trying to run an X application from an xterm and you get some or all of the following messages:

Xlib: connection to ":0.0" refused by server
Xlib: Invalid XDM-AUTHORIZATION-1 key (failed key comparison)
Gtk-WARNING **: cannot open display: :0.0
Xlib: connection to "linux:0.0" refused by server
Xlib: No protocol specified

Everyone suggests things which "should work":

$ export DISPLAY=hostname:0.0
$ xhost +localhost

However, none of them work. You discover that you only have the problem when logged in as root. However, you need to be logged in as root, for example because you are installing Mozilla, and you are supposed to run it once as root to make sure that all the files are created to allow it to be run by other users.

The solution is to export the DISPLAY, etc., BEFORE logging in as root. That is, issue those commands when logged in as a regular user, THEN issue a `su' command to gain root privileges.

Click here to return to Thomas Hedden's home page

Copyright © 2003-2017 Thomas Hedden

This page is viewable with any browser.

Valid XHTML 1.0!

Valid CSS!