Xlib: connection to “hostname” refused by server


In order to see X clients, you must have proper access. This is done by the use of an MIT MAGIC COOKIE in the .Xauthority file.

If you are connecting to a secondary machine or changing users (for example suing to root), you may need to transfer the cookie to the remote machine before your DISPLAY will appear. Otherwise, you may get an error such as:

Xlib: connection to “hostname:0.0” refused by server
Xlib: No protocol specified

Local Machine Access

Switching users on a local machine is a common task. This task is so common that a script has been created and incorporated into several linux distributions (notably Debian)

The script will automatically transfer your cookie for you.

Download sux at
http://fgouget.free.fr/sux/sux

Remote Machine

Note transferring the cookie via ssh is automatic.

From a terminal

bash$ echo $DISPLAY
:0
first$ xauth list $DISPLAY
first.server.com/unix:0 MIT-MAGIC-COOKIE-1 076aaecfd370fd2af6bb9f5550b26926
first$ telnet second.server.com
login:
Password:
second% setenv DISPLAY first.server.com:0
second% xauth add first.server.com:0 . 076aaecfd370fd2af6bb9f5550b26926

More information regarding xauthentication can be found here:
http://tldp.org/HOWTO/Remote-X-Apps-6.html