X11: Exporting a display

How can I make my X11 display go to another machine ?

Oh well, something everyone should know, but sometimes you have surprises !

Instructions follow …

A (very) short description of X11

The X11 protocole is client/server by nature. On one side there is the server, which will actually do all the display and input processing (keyboard, mouse and such) and on the other side there are the clients.

The clients are just any X11 programs, which will connect to the X11 server in order to get to display something and get user interactions.

Setting a client to attach to a remote server

Now you might want a client running on a machine to connect to an X11 server running on another machine. This is a frequent situation, just imagine that the application runs on a remote server in a server room and user interaction is made on a workstation.

But hold on… in that situation who is the X11 client and who is the X11 server ?

The X11 client is the program running on the remote server machine. The X11 server is the workstation. In fact, the client program will connect to the X11 server running on the workstation to have all input/output there.

When you get this straight, the following is quite natural. All you have to do is instruct the X11 client program to use another X11 server, you do this by either of the two ways :

  1. setting the DISPLAY environment variable and running the X11 client program : $ DISPLAY=workstation:0.0 ./client
  2. or by instructing the client program to do so by a command line switch : ./client --display workstation:0.0

Simple ?

But in most situations this will naturally fail. The reason is that most X11 server won’t let a remote client connect for security reasons (this would allow a program to spy the activity on the X11 server). So you have to explicitely allow this connection.

Allowing remote clients to connect

You can do this by either of two ways :

  1. using the xhost : $ xhost +server will allow any client from server hostname to connect to the X11 server. This will obviously work, but is not very safe as any client from the server machine is allowed to connect to the X11 server
  2. using the mit-magic-cookie : the magic cookie is a kind of key to your X11 server and this will be explained in a future post.

One thought on “X11: Exporting a display”

Comments are closed.