Chapter 22. SSH, FTP, VPN, & Web Sharing

Email and Web surfing may be the most popular Internet activities, but the world’s most gigantic network has many other uses. The general idea is always the same, though: letting one computer reach out and touch another.

Mac OS X offers a few features that embrace the more literal aspects of that notion. For example, you can turn your Mac into a Web server—an actual living Web site that anyone on the Internet can visit. This chapter also explores various advanced methods of manipulating your own Mac from the road, including remote access technologies like long-distance file sharing, FTP, SSH, and virtual private networking (VPN).

Note

Most of these technologies are designed for full-time Internet connections (cable modem or DSL, for example). If you have a dial-up modem, these features work only when you’re actually online. Still, they may occasionally be useful anyway. You could always get online, call up a friend and say, “Check out my Web site right now—here’s the current IP address” or call someone back home to say, “I have to grab a file off my hard drive. Could you make the Mac on my desk go online?”

Using the Sharing pane of System Preferences, you can turn your Mac into a Web site (or server), accessible from the Web browsers of people on your office network, the Internet at large, or both.

This feature assumes, of course, that you’ve already created some Web pages. For this purpose, you can use Web design programs (Apple’s Pages, for example) or save documents out of TextEdit or Word as Web pages. Or you could let Mac OS X build Web pages for you using iPhoto or Image Capture.

After you provide your friends and coworkers with your Mac’s Web site address, they can view your Web pages, graphics, and documents in their own Web browsers. And whenever you’re online, your Web site is also available to anyone on the Internet—but you don’t have to pay a penny to a Web-hosting company.

Mac OS X’s Web Sharing feature isn’t some feeble junior version, either. Inside Mac OS X is Apache, one of the strongest and most popular Unix Web server programs—precisely the same one that drives 60 percent of the Internet’s commercial Web sites.

The bottom line: If you build it, they won’t necessarily come. But you’ll have the capacity to handle them if they do.

Here’s how you turn your Mac into a low-budget Web site:

  1. Put the HTML documents, graphics, and files you want to publish into your HomeSites folder.

    Every account’s Home folder has a Sites folder, and therefore the Mac can actually serve up lots of Web sites at once.

    Your Web site’s home page, by the way, won’t appear unless it’s named index.html. (Apple has already put an index.html document into your Sites folder, just to give you the idea; feel free to replace it.) And the other files you put in Sites aren’t accessible unless they’re linked from your index.html page.

  2. Open System Preferences; click Sharing. Turn on the Web Sharing checkbox (Figure 22-1).

    You’ve just made the contents of your Sites folder available to anyone who connects to your Mac.

  3. Send your network address to your friends and coworkers.

    People on your local office network can use your Mac’s Bonjour name to connect. It appears at the top of the Sharing pane, as shown in Figure 22-1. For example, your colleagues can type http://office-mac.local/~chris into their Web browsers, where office-mac.local is your Mac’s Bonjour name.

    If other people will be connecting from the Internet, you need to figure out your public IP address; as noted in the box on The IP Address Mess: Port Forwarding, that might be your router’s IP address, not your Mac’s.

    Your Mac Web site’s address might be, for example, http://111.222.3.44/~chris/ (the number is your public IP address, and the name should be your short user name). Don’t forget the final slash. Tell your friends to bookmark it so they won’t have to remember all that.

You’ve just put your Mac-based Web page on the Internet for all to see—that is, all who know your secret Web address. Maybe you’ll want to distribute the address only to other people on your office network, using your tiny Web site as a distribution source for documents. Or maybe you’ll want to go whole-hog, hosting an e-commerce Web site (read on).

The instructions above show you how to create a Web site in your Home→Sites folder. In other words, they guide you through the process of creating a personal Web site.

But if you have an Administrator account (Chapter 12), you can also put your Web pages into the main hard drive window’s Library→WebServer→Documents folder. This is your Mac’s main Web site folder, and its address is simply, for example, http://111.222.3.44/. That is, it’s just your public IP address, no user name needed. (Here again, if people will be connecting from across your office network, they can replace the IP number with your Mac’s Bonjour name.)

Working with this primary Web site folder is only slightly different from the personal ones described above. Because you’re now working inside an official Mac OS X system folder, you must mind your permissions. Using the File→Get Info command, you should set up the permissions of any folders and documents inside the Library→Web-Server→Documents folder (an Images folder, for example) as described on The Get Info method.

That way, you can ensure that you’re in control of which visitors are allowed to do what with your Web documents.

FTP sites (file transfer protocol) store pieces of software that can be accessed from the Internet. If you’ve heard of FTP at all, it was probably under one of two circumstances—either you’ve downloaded software from an Internet FTP site, or you’ve created and maintained your own Web site.

You can also connect to your Mac’s regular File Sharing feature (Chapter 13) from over the Internet. This feature is a blessing to anyone who travels, whether with a laptop or to a branch office, because you’ll never be up the creek without a paddle if you discover that you left an important file at home.

The easiest way to go about it is to use Back to My Mac, which is one of Apple’s MobileMe services.

If you’d rather spend time than money, though, you can set up a remote file-sharing system on your own. Start by setting up the home-base Mac for file sharing, as directed in Chapter 13; then figure out your Mac’s public IP address, as described in the box on The IP Address Mess: Port Forwarding.

Finally, once you’re on the road, go online and proceed like this:

Are you a geek? Take this simple test at home. Do you get excited about Mac OS X’s ability to permit SSH access?

If you answered “What’s SSH?” or “I’m already being quiet,” then the following discussion of Unix remote control may not interest you. To be sure, SSH is not a program with a graphic user interface (icons and menus). You operate it from within a program like Terminal by typing commands, exactly as described in Chapter 16.

If you’re willing to overlook that little peccadillo, though, SSH (Secure Shell) is an extremely powerful tool. It lets you connect to your Mac from anywhere—from across the network or across the Internet. And once you’re connected, you can take complete control of it, copying files, running commands, rearranging folders, or even shutting it down, all by remote control.

Here’s how you go about using SSH:

  1. Set up your Mac by opening the Sharing panel of System Preferences, and then turning on the Remote Login checkbox.

    You’ve just told the Mac it’s OK for you (or other people with accounts on your machine) to connect from the road. Quit System Preferences.

  2. Go away.

    You can move to another machine on the network, or another computer on the Internet (if you’ve dealt with the port-forwarding issue described on Web Sharing). Once you’re online with that other machine, you can contact your home-base machine from within a program like Terminal.

  3. At the prompt, type ssh -l chris 111.222.3.44. Press Return.

    Instead of chris, substitute your short account name (as you’re known on the Mac you’re tapping into), and replace the phony IP address shown here with your real public address. (If your Mac back home has a domain name unto itself, such as macmania.com, you can type that instead of the IP address. And if you’ve turned on port forwarding, use your cable modem/DSL box’s IP address.)

    If all goes well, the ssh command acknowledges your first successful connection by displaying a message like this: “The authenticity of host ‘111.222.3.44 (111.222.3.44)’ can’t be established. RSA key fingerprint is d9:f4:11:b0:27:1a:f1: 14:c3:cd:25:85:2b:78:4d:e7. Are you sure you want to continue connecting (yes/ no)?” (This message won’t appear on subsequent connections.) You’re seeing SSH’s security features at work.

  4. Type yes and press Return.

    Now you see one more note: “Warning: Permanently added ‘111.222.3.44’ (RSA) to the list of known hosts.” You’re then asked for your account password.

  5. Type your account password and press Enter.

    You’re in. Issue whatever commands you want. You can now conduct a full Unix Terminal session as described in Chapter 16—but by remote control.

One of the most common uses of SSH is quitting a stuck program. Maybe it’s a program that doesn’t respond to the usual Force Quit commands—maybe even the Finder or Terminal. Or maybe, having just arrived in Accounting on the fifth floor, you realize that you accidentally left your Web browser, open to Dilbert.com, up on your screen in clear view of passersby.

In any case, you’d fire up Terminal and proceed like this (what you type is shown in bold; the Mac’s responses are in normal type):

home-mac:~ chris$ ssh 172.24.30.182
The authenticity of host '111.222.3.44 (111.222.3.44)' can't be
established. RSA key fingerprint is d9:f4:11:b0:27:1a:f1:14:c3:c
d:25:85:2b:78:4d:e7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.24.30.182' (RSA) to the list of
known hosts.
chris@111.222.3.44's password: fisheggs
Last login: Thu Apr 22 17:23:38 2010
Welcome to Darwin!
office-mac:~ chris$ top -u

The top -u command, as described in Chapter 16, displays a list of running programs. After a block of memory statistics, you might see a list like this:

294 top        6.5% 0:01.10 1  16   26   276K   416K   652K  27.1M
293 bash       0.0% 0:00.03 1  12   15   168K   856K   768K  18.2M
292 login      0.0% 0:00.01 1  13   37   140K   408K   492K  26.9M
291 Terminal   0.0% 0:05.50 3  60  115  2.99M  5.41M  6.59M   149M
287 HotKey     0.0% 0:00.34 4 151   78   760K  2.24M  2.67M  96.5M
283 Finder     0.0% 0:02.04 2  89  162  3.95M  17.1M  15.5M   165M
282 SystemUISe 0.9% 0:01.51 2 241  327  3.03M  7.85M  8.54M   158M
281 Dock       0.0% 0:00.24 2  77  132   780K  10.7M  2.80M   139M

As you can see, the Finder is process number 283. If that’s the stuck program, then, you could quit it like so:

office-mac:~ chris$ kill 283

Or if you’re sure of the program’s exact name, just use the killall command with the program’s name instead of its process ID. To handle a stuck Finder, you would type this:

office-mac:~ chris$ killall Finder

Either way, the Finder promptly quits (and relaunches in a healthier incarnation, you hope). You could also, at this point, type sudo shutdown -h now to make your Mac, elsewhere on the network, shut down. (Terminal doesn’t type any kind of response.)

If you ended your SSH session by shutting down the other Mac, you can just close the Terminal window now. Otherwise, type exit to complete your SSH session.

After reading the previous pages, you might assume it’s a piece of cake for businesspeople to connect to their corporate networks across the Internet from wherever they happen to be: their homes, hotel rooms, or their local Starbucks. But even though the steps on the preceding pages work fine if you’re dialing into your home machine, they’ll probably fail miserably when you want to connect to a corporate network. There’s one enormous obstacle in your way: Internet security.

The typical corporate network is guarded by a team of steely-eyed administrators for whom Job Number One is preventing access by unauthorized visitors. They perform this job primarily with the aid of a super-secure firewall that seals off the company’s network from the Internet.

So how can you tap into the network from the road? One solution is to create a hole in the firewall for each authorized user—software that permits incoming Internet traffic only from specified IP addresses like your Mac’s. Unfortunately, this setup isn’t bulletproof, security-wise. It’s also a pain for administrators to manage.

Back in the dial-up modem days, you could dial directly into the corporate network, modem-to-modem. That was plenty secure, but it bypassed the Internet, and therefore wound up being expensive. (Want proof? Try this simple test: Make a call from the Tokyo Hilton to the Poughkeepsie Sheet Metal home office. Have a look at your hotel bill when you check out.)

Fortunately, there’s a third solution that’s both secure and cheap: the Virtual Private Network, or VPN. Running a VPN allows you to create a super-secure “tunnel” from your Mac, across the Internet, and straight into your corporate network. All data passing through this tunnel is heavily encrypted; to the Internet eavesdropper, it looks like so much undecipherable gobbledygook.

And it’s free—whether you’re accessing the Internet via your home DSL, a local ISP number from a hotel, or wirelessly from your stool at Starbucks.

Remember, though, that VPN is a corporate tool, run by corporate nerds. You can’t use this feature without these pieces in place:

If you’re lucky, your company’s network geek has provided you with a VPN settings file, a little double-clickable icon that automatically opens the Network pane of System Preferences and fills in the blanks for you. If not, you can do all that manually:

  1. Open System Preferences. Click Network. Click the button below the list of connections at the left side.

    The “Select the interface” sheet appears.

  2. From the pop-up menu, choose VPN.

    Now a new pop-up menu appears, called VPN Type; you’re supposed to choose either L2TP (Layer 2 Tunneling Protocol), PPTP (Point to Point Tunneling Protocol), or Cisco IPsec (IP Security). Find out which system your company’s network uses.

  3. Choose the type of VPN from the VPN Type pop-up menu. Type a name for this connection (it can be anything you want). Click Create.

    You return to the main Network pane, where the settings boxes for your VPN are waiting (Figure 22-5).

  4. Fill in the server address and account name. Click Authentication Settings to specify your password and other security settings.

    Here, for example, is where you indicate that you have one of those SecurID cards.

  5. Click OK. Turn on “Show VPN Status in menu bar.”

    That checkbox makes the VPN menulet appear; it’s your ticket to getting connected (Figure 22-5, top).

Close System Preferences. You’re ready to connect.

Connect the way you normally do—via cable modem, DSL, office network, modem, AirPort, or whatever. Once you’re online, choose your VPN’s name from the VPN menulet. You’ll be asked for your credentials: your password, for example, or the code displayed on your SecurID card.

If all goes well, several status messages go by. The last one says, “Connected To” and gives the IP address of the network equipment you’ve reached out and touched.

At this point, you’re connected to the corporate network. You can perform the same network-related tasks you could if you were actually in that office: Check your email, view internal corporate Web pages, access internal FTP servers, make printouts on laser printers thousands of miles away, and so on.

You generally can’t browse things, though. That is, depending on your network, you might not be able to use your Sidebar to view a list of the other computers on the office network, or see a list of networked printers.

In this case, to access these services, you must know their IP addresses. For example, to connect to a shared folder on another computer, choose Go→Connect to Server, type its network address, and press Return.

When you’re finished accessing the remote network, choose Disconnect from the VPN menulet. (Accessing other Web sites can be slow while you’re on a VPN.)