Run Software on Different Linux Machines With "xhost"

Man using laptop computer
PhotoAlto/Sigrid Olsson / Getty Images

In contrast to the typical use of Windows-based home computers, in Linux/Unix environments, working "on the network" has always been the norm, which explains the powerful networking features of Unix and Linux operating systems. Linux supports rapid and stable connections to other computers and running graphical user interfaces over the network. 

The primary command for executing these network activities is xhost—the server access control program for X.

The xhost program is used to add and delete host (computer) names or user names to the list of machines and users that are allowed to make connections to the X server. This framework provides a rudimentary form of privacy control and security.

Usage Scenario

Let's call the computer you are sitting at the "localhost" and the computer you want to connect to the "remote host." You first use xhost to specify which computer(s) you want to give permission to connect to (the X-server of) the localhost. Then you connect to the remote host using telnet. Next, you set the DISPLAY variable on the remote host. You want to set this DISPLAY variable to the local host. Now when you start up a program on the remote host, its GUI will show up on the local host (not on the remote host).

Example Use Case

Assume the IP address of the local host is 128.100.2.16 and the IP address of the remote host is 17.200.10.5.

Depending on the network you are on, you may also be able to use the computer names (domain names) instead of the IP addresses.

Step 1. Type the following at the command line of the localhost:

% xhost + 17.200.10.5

Step 2. Log on to the remote host:

% telnet 17.200.10.5

Step 3. On the remote host (through the telnet connection) , instruct the remote host to display windows on the local host by typing:

% setenv DISPLAY 128.100.2.16:0.0

(Instead of setenv you may have to use export on certain shells.)

Step 4. Now you can run software on the remote host. For example, when you type  xterm on the remote host, you should see an xterm window on the local host.

Step 5. After you finish, you should remove the remote host from your access control list as follows. On the local host type:

% xhost - 17.200.10.5 

Quick Reference

The xhost command contains just a few variations to help you with your networking:

  • xhost + hostname: Adds hostname to X server access control list.
  • xhost - hostname: Removes hostname from X server access control list.
  • xhost + : Turns off acccess control (all remote hosts will have access to X server)
  • xhost - : Turns access control back on.

Because Linux distributions and kernel-release levels differ, use the man command (% man) to see how xhost is implemented in your particular computing environment.