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.

1 thought on “When root cannot run X applications from a local terminal”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.