oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Hands on X11
Pages: 1, 2

Networking X11

In the old days, your big Unix servers ran all of the applications, and you used an X Terminal (a machine with a screen and keyboard but no hard drive or CPU of its own) to use those applications.

Today most Unix systems (Mac OS X included) still support this functionality. Let's go back to your open xterm window. In order to allow other systems to display their applications on your screen, you must first give them permission to do so. You do this using the xhost program (you can learn more about the xhost command by typing man xhost at the xterm prompt). From the command prompt in xterm, type xhost and press return. Unless you've already modified the default permissions of your system, you'll most likely see a message like this:

access control enabled, only authorized clients can connect

What this tells us is that your system will only let authorized computer systems display X11 applications on your system. For security purposes, this is a very good thing. You wouldn't want someone displaying applications on your system without your authorization. In order to allow other machines to do this, you need to grant them access from the prompt. For example, I'd like to allow Gomez, a FreeBSD server without a monitor or keyboard, to display it's applications on my Mac. Gomez's IP address is, so I type xhost + at the prompt, and it responds with being added to access control list

Alternatively, if I'm sure that my network is secure behind a firewall, and I'm not worried about possible security issues, I could also have typed xhost + at the prompt. This allows any and all machines to use my Mac's display. The system would respond with

access control disabled, clients can connect from any host

Now I'm ready to launch an application from the remote system. I've ssh'd to Gomez, where an entire X11 distribution and additional applications are available to me. So, let's launch something simple, xclock for example, and watch it appear on my Mac. I type xclock & at the Gomez command prompt and press return, but instead of seeing an xclock appear on the Mac, I get this error:

Error: Can't open display:

The cause of this error is that all X11 systems, by default, will try and use their own display for any X11 applications you launch. In the case of Gomez, there is no keyboard, mouse, or monitor, and no X Server running. So I need to tell Gomez to use my Mac's display instead. The Mac's IP address is, so, from Gomez's command prompt, I type:

export DISPLAY=

I use the export command for this because I'm running the bash shell. If I were running the tcsh shell, I'd have typed:


In either case, unless something went wrong, the system should return a command prompt, and you're ready to go. This command tells the remote system to use the first X Windows display running on the machine with the IP address of In other words, it treats the Mac as if it were its very own monitor, keyboard, and mouse. Now, we type:

xclock &

This time, instead of an error, Gomez returns a process number (we ran the program in the background using the & symbol) and we see the xclock display on the Mac.

Screen shot.
X11 xclock.

Neat, but not exciting. And we've already got the xclock application on our Mac. On this Mac, we use Safari, Camino, and Internet Explorer, but don't have Mozilla installed. Wouldn't it be neat to run FreeBSD's Mozilla on the Gomez and have it display on the Mac? From the command line, we type mozilla &.

The server responds with a process number, and after a few moments, Mozilla appears on the Mac's screen, as shown in this screenshot. Notice the un-Mac-like fonts, and the information on the about page which lists "FreeBSD i386" as the build version. This is because Mozilla is actually running on the FreeBSD server and is merely being displayed on the Mac.

X11 can be used to manage many remote Unix systems in this fashion, an unlimited amount, actually, all the while keeping your Mac's system resources low (only the X11 application runs locally). This is very handy when running applications on Unix systems that lack a monitor and keyboard but require a graphical display. The Oracle installation program is an excellent example of this type of application.

Final Thoughts

We've only just scratched the surface of X11's true potential. Not only do you now have the ability to run a huge collection of X11 applications on your Mac, but you can also run an X11 application from any Unix system you can connect to.

Dan Benjamin is a business strategist, programmer, writer, interface designer, and photographer.

Return to the Mac DevCenter.