SSH on Mac OS X for Worry-Free Wireless

Network security for projects such as webcam broadcasting isn't as much of an issue when your device is hard-wired into the desktop computer sitting on your office desk. But if you set up a wireless transmitter using an 802.11b network as described in my last article, The Industrial-Strength Wireless Webcam, you need to evaluate your environment and establish the appropriate level of security.

Once you start sending private data over the radio waves, such as your FTP user name and password, you are increasing the likelihood that some unauthorized snoop can "listen in" and grab your data.

In most home 802.11b situations, I still believe that the combination of common sense and the use of WEP provides you with the security you need for broadcasting to your hobby Web site. But what if you want to use a webcam in public and send images to a business site? Certainly you don't want to take a chance on compromising security.

In situations like this, the Unix underpinnings of Mac OS X begin to show their value. In this article, I'm going to suggest a safe solution for broadcasting your webcam images, or any other data for that matter, using the Terminal application in Mac OS X to establish a secure connection with your Web server.

Since we're talking Unix here, these techniques will work in any command line environment capable of using SSH, and we're definitely not limited to using Mac OS X for this project. So let's pop the hood and get to work.

A few words about SSH and SCP

Do those of you who have some experience using pico and Mac OS X have any additional pointers?

SSH Secure Shell is a protocol for secure remote logins. Its key function is to prevent hackers from stealing passwords that give them unauthorized access to Web sites. SSH does this by encrypting the data (including passwords) to eliminate eavesdropping. It connects to the specified hostname, making the user prove his/her identity to the remote machine.

Once the SSH connection is established, SCP (secure copy) copies files between hosts on a network. It uses SSH for data transfer, and uses the same authentication by asking for passwords or phrases.

Mac OS X users can set up these secure connections via the Terminal application. If you haven't worked with command lines before, I suggest that you you practice first by building a couple of basic scripts. You can get more information on this from a variety of places, such as the Project Freedom Web site, or via downloadable PDFs such as Griffman's Terminal Guide. Once you're comfortable with the Terminal application, then you're ready to set up a SSH session.

Setting up your secure session on Mac OS X

Once you have the webcam software saving to a file in the filesystem, you're ready to set up ssh for public key operation. Both ssh and scp use the same keys to do their work, so once ssh is set up, scpwill work.

These steps assume that you don't have any other keys present on your Web server. If you do, then you already know what you're doing, and don't need this article... =)

1) Generate a new key:

rob@entropy$ ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/home/rob/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rob/.ssh/id_dsa.
Your public key has been saved in /home/rob/.ssh/id_dsa.pub.
The key fingerprint is:
33:3c:5c:41:98:1b:fc:f5:9e:69:56:2e:0b:f1:24:7f rob@entropy

* At this point, if you've never used ssh from your OS X box before, you'll be prompted to verify the fingerprint of the server's key. Answering "yes" will save the server's fingerprint in a local cache. Should the fingerprint ever change, ssh (and scp) will sound an alarm, as this could be an indication of a man-in-the-middle attack in progress.

* You will be prompted for your password on the Web server. Enter it, and the key file will be copied.

* It should log you in without a password. If not, check your work. Also check that your Web server allows public key exchange (it's on by default, and is rarely disabled. Check with your friendly local sysadmin if you're not sure.)

* It should copy the file without asking for a password. The syntax is:

scp [source file] [hostname]:[destination directory]

* This example also assumes that you have the same username on your Mac OS X client as on your Web server.
If not, you can also specify a different username on the scpcommand line. For example, if your login on the Web server is webadmin:

7) In five minutes, check your Web site with a browser. The updated picture should magically appear. Congratulations! Your webcam images are now being updated over a cryptographically secure channel, safe from wireless eavesdroppers.

When you are finished with your webcam, it's a good idea to tell cron to stop trying to update your Web site. To disable the cron entry, run another crontab -e in your terminal window, and comment out the line with a # symbol:

# */5 * * * * /usr/bin/scp /path/to/my/webcam.jpg

Now, whenever you want to start the auto-update process again, just delete the #, and away you go.

If you have trouble getting it going, there are excellent man pages available for ssh-keygen, ssh, and
scp. You might also take a look at Rob's article on using SSH with wireless networks.

Final thoughts

This probably feels like a lot of work just to set up a webcam session. But the risks of transmitting unsecured data over a public network far outweigh the effort to set up ssh/scp. The good news is, once you've established your system, it's easy to turn on and off. As a bonus, with ssh keys in place, you can securely copy files and log in to your Web server without needing to use passwords.

If you discover a clever workaround that saves time or improves performance, be sure to let us know via the TalkBacks.