Ubuntu Wireless AirTunes

I've got an older Thinkpad laptop that was collecting dust in a cabinet, so I decided to set up an Airplay server so that I could have easy access to my speakers (a set of Logitech Z2300's from my freshman year at MIT that are still kicking ass). I decided to run an instance of Ubuntu Server 12.04 and to use Shairport.

Unfortunately, my apartment has miserable wiring. The only power sockets are at head height... and there are only 3 in the entire apartment. Easy ethernet routing? In my dreams.


That meant I needed to set up the wireless adaptor on the laptop to use WPA2, which lead to a bunch of random research1, and eventually this worked. So here goes.

First, you need to make sure you have wpa_supplicant. If you don't, a simple sudo apt-get install wpasupplicant should do the trick.

Then, you need to find pre-compute your PSK entry from your ASCII passphrase. To do this, use wpa_passphrase NETWORKNAME PASSPHRASE, which should give you the following output:


That value for PSK is what we're really after.

Once you have your PSK, it's a simple step of configuring your /etc/network/interfaces file with your network preferences. I'm going to be using a static IP, but you could just as easily use DHCP.

# /etc/network/interfaces

auto wlan0  
iface wlan0 inet static  
    wpa-ssid NETWORKNAME
    wpa-psk  04f71ceab8c0ba20b5ec1cc265d0f0ee92996c57287cb6fc3e44ff9258f67171
    wpa-ap-scan 1
    wpa-key-mgmt WPA-PSK

A quick run-down of these settings:

  • wpa-ssid: The SSID of your router
  • wpa-psk: The PSK computed using wpa_passphrase
  • wpa_ap_scan: Set to 1 unless your SSID is hidden, in which case use 2
  • wpa-key-mgmt: WPA-PSK unless you're using a radius server

Not all of these settings may be needed, but these settings worked for me. In addition, you might need to disable your wired connection by commenting out the eth0 section in /etc/network/interfaces (or removing it).

Sidebar: I picked up a nice trick for passing text between two computers quickly when you don't have the luxury of a GUI.

By using netcat as a server on one, and piping output from another, you can easily and quickly send text across (it's how I got the output of these commands to my Macbook).

For example:

# Run on receiver (at
nc -l 6000

# Run on sender (after receiver is listening)
echo "text" | nc 6000  


The second challenge I found was that my sound card wasn't properly configured. To fix this, I used two tricks:

  1. Add your user to the audio group with: sudo adduser USER audio (don't forget to reboot).
  2. sudo apt-get install alsa-utils, and then make sure that your audio card isn't muted with alsamixer.

To test that your audio device is configured, you can use speaker-test, which plays white noise. If you can hear sound, you're good to go.

Finally, once Shairport was running, it still wouldn't accept connections. To fix this, I had to install & run the avahi-daemon with sudo apt-get install avahi-daemon. After that, everything just worked.

1. The most useful information came from Nicolas Bernaerts.