When root cannot run X applications from a local terminal

I run XWindows on a CentOS 5.9 box as a non-root user. To perform administrative tasks, I occasionally log in as root using “su” in a terminal window. However, I found that I was unable to start any GUI applications as root. I got the following error:

Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

E233: cannot open display Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

This can happen when xhost isn’t configured to allow local, non-network connections. As the user who started the xwindows session (not root) run:

$ xhost
access control enabled, only authorized clients can connect
INET:localhost.localdomain
SI:localuser:cfinch

This shows that network connections to X are only allowed from localhost, and from a local user called cfinch (who started the X server). To fix the problem, run the following command to allow local user “root” to connect to the X server:

$ xhost local:root
non-network local connections being added to access control list

To see what this did, run xhost without any arguments:

$ xhost
access control enabled, only authorized clients can connect
LOCAL:
INET:localhost.localdomain
SI:localuser:cfinch

Now root can run GUI applications, such as the system-config-* tools.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s