Configuring X forwarding between BSD and Windows

On Unix systems, windowing systems are an optional component. There are numerous window systems but the most prevalent, as I understand it, is X. It’s a networked client/server model, where the machine with the display and input devices is called the server, and the machine running windowed apps against this server is the client. This is backwards from how you typically think about clients and servers, i.e. servers are usually headless and clients are usually responsible for rendering data from servers and translating input.

I usually interact with my BSD machine from my Windows laptop using PuTTY. But running Emacs in a terminal window is sometimes hard on the eyes, it’s hard to get good fonts, color schemes, etc. I wanted to see if I could launch Emacs from PuTTY but have it render its UI over the X protocol on my Windows laptop. This was harder than I thought, and I didn’t find any step-by-step tutorial to help me troubleshoot, so here’s an account of what worked for me. Note that I started from a relatively clean install of FreeBSD 10.1, with only sshd and some basic packages installed.

To prepare the BSD machine for acting as an X client, I had to install the xauth package:

$ sudo pkg install xauth

The only visible result of this is the addition of the DISPLAY environment variable in upcoming SSH sessions, set to its default localhost:10.0.

Now to set up the X server, i.e. my Windows laptop. First I installed Xming from SourceForge. I opted not to include any bundled PuTTY, as I already had it installed.

Then I configured the PuTTY connection to my BSD machine to do X11 forwarding, see screenshot below:

PuTTY X11 forwarding configuration

PuTTY X11 forwarding configuration

(don’t forget to save that setting on the connection in question.)

I installed the xterm package on my BSD machine to have a simple app to test this setup. Here’s what the workflow looks like to run an X application on the BSD box showing its UI on the Windows side:

  • Connect with PuTTY, using a connection with X11 forwarding
  • Start Xming on the Windows box (this is the X server responsible for rendering the UI of the remote app)
  • Start the application from the shell, e.g.
$ xterm

After a short delay, the xterm application should show a window on the Windows desktop. Note that the app is executing on the BSD box, but showing its UI over the networked X11 protocol via Xming on Windows.

Now I just need to figure out how to set up nicer fonts and coloring in this environment.


A Unix diary

A few years ago I decided to abandon Windows after having seen how much more versatile the Unix development model is. People seem to struggle less with inadequate tools, and given the philosophy of openness and freedom, the best tools are widely available at no cost.

I knew this would be hard for me, I’m a creature of habit, so I’ve spent the past couple of years using Emacs and Unix command-line tools on Windows to ease the transition to a Visual Studio-free environment.

So about a month ago I bought a new desktop machine, now standing in my basement, and installed FreeBSD 10.1. I chose BSD because it seems to be a more strongly curated Unix than the various Linux distros, for example, and with a generally likeable user community.

I thought I’d write a couple of short posts detailing things I’ve learned about the setup and configuration for posterity. That’s also why I’ve fallen back to English, hopefully these posts can help other Windows-BSD converts get started, even outside of Sweden :-)