Xauth

From LQWiki
Jump to navigation Jump to search

The xauth program is used to provide remote applications with a numerical cookie (a password of sorts) so that your local X server will allow them to directly display and receive keystrokes, mouse clicks, and other events. Without the cookie, the remote application will be refused (unless the xhost command was used to allow the remote host). In addition to having the proper cookie, the remote applications must be told where the local X server is through the setting of the DISPLAY variable.

For many applications, ssh provides an excellent alternative to using xauth to allow the remote applications. Ssh will automatically set the DISPLAY variable, provide a temporary xauth cookie, and shuttle the communications through the encrypted connection. Using a direct connection and xauth removes the encryption, but allows faster throughput and response times.

Using xauth

To use xauth, the X server must have been started with it enabled. This is usually true if you log in with xdm, gdm, etc. or if you use startx from the console command line (xinit may or may not enable xauth).

To find out what the cookie is, run the following command:

MyLinuxBox$ xauth list
MyLinuxBox/unix:0  MIT-MAGIC-COOKIE-1  7baa0cff510bd092cdce4286e72356df
MyLinuxBox.mycompany.com:0  MIT-MAGIC-COOKIE-1  7baa0cff510bd092cdce4286e72356df
MyLinuxBox/unix:10  MIT-MAGIC-COOKIE-1  e2de05a5fa80f36772f8b08419e3c926

The one that matches your DISPLAY variable is the one you want. Extras may be left around by ssh and are likely not valid any more.

Once you know the cookie, log in to the remote machine. Then set the cookie using cut-and-paste:

OtherBox$ xauth add MyLinuxBox.mycompany.com:0 MIT-MAGIC-COOKIE-1 \
   7baa0cff510bd092cdce4286e72356df
OtherBox$ export DISPLAY=MyLinuxBox.mycompany.com:0

(If you use csh, use the proper syntax instead of the export command.) The DISPLAY variable must match the entry that xauth enters, which may be slightly different than how you typed it.

Another way of transferring the xauth cookie is mentioned in the xauth man page.

External links