Connecting to SSCC Linux Computers using X11 in Mac OS X

X11 is a program that allows Macs to display Linux graphics. This is a requirement for using Stata, SAS and many other programs in interactive mode. X11 is included in the standard distribution of Mac OS X 10.3 or higher.

This article will explain how to set up X11 to connect to the SSCC's Linux servers. Following these steps will also automatically correct the operation of the backspace key; turn on color-coding in emacs for editing Stata, SAS, and various programming language files; and adjust some default settings to improve usability. Copy and paste procedures within and between X11 and Mac windows, and how to move Linux graphics to the Mac, are also explained. Once you make the changes described here you will be able to access Stata, SAS and other programs using their full graphic capabilities from your office, home or elsewhere, though a broadband connection such as DSL or cable is highly recommended.

Note that you could also use the Mac's Terminal program (see below) to access SSCC's Linux computers and just have X11 display graphics when needed. Unlike X11, Terminal uses the standard Mac copy and paste commands. But this would still require you to install X11 and start it in the background each session. Using X11 alone provides a more integrated computing experience and is not difficult to set up.

Overview

Like the SSCC's Linux computers, modern Macs run on a Unix operating system. They use many of the same setup features as Linux computers, and are operated in the same way if the graphical interface is not used. All of the Linux commands that you are likely to know are also Mac commands, since they are just generic Unix commands (though they do have different options between the systems). You will be using generic Unix commands to make the needed changes in both your Linux and Mac home directories. Since the purpose is to get you connected to a Unix (Linux) system, you shouldn't have too much trouble using Unix (Mac) commands to do the set up.

The Mac's Terminal program provides a text-based interface that you can use to operate both the Mac and the Linux systems during set-up. It should be located in the Utilities folder inside the main Applications folder on your Mac. Double-click it to start it up, and then follow the instructions from step 2 below, typing commands as though you were in any other Unix operating system.

You will be adding or modifying some settings files, so be careful. Following the instructions will preserve your existing settings files, in case you want to restore them. You will need to add a line to at least one settings file. If you know how to use one of the usual Unix text editors, namely, emacs, pico, ed or vi, decide which one you prefer, and type its name in the Terminal to start it up. (All four editors come with Mac OS X, installed and ready to use. Pico is nearly self-explanatory once started; those symbols at the bottom indicate Control-key combinations, so hold down the Ctrl key and type G to get help.) If you would like to avoid using an editor, the instructions below will describe how to make the changes without one.

It probably cannot be overemphasized that Unix (Mac or Linux) commands must be typed exactly as instructed. Be especially careful to observe spacing (or lack of spacing) between parts of the commands, and to watch for the smallest details, like period symbols, ".", which may or may not be separated from other parts of a command by spaces. Capitalization counts: you must use the exact combination of lower and upper case letters shown. You will not have to do much typing for this setup, however, since the complicated commands are available in files available on the SSCC's web server that you will just copy to your directories. Still, be careful not to make typing mistakes.

Installing and Configuring X11

  1. Install X11 on your Mac, unless it is already in the Utilities folder inside the Applications folder. To do this, close all running applications, insert your OS X 10.3 (or later) installation disk in your computer, and do a Custom Installation, selecting X11 when the opportunity is presented. This will not change or overwrite your other system files.

  2. Open the Mac's Terminal program (again, in Utilities which is in Applications), type pwd, and hit the Return key. You should see /Users/{yourusername} on the next line, with your own user name replacing {yourusername}. If you don't see that, type cd and hit Return, and try pwd again. You are now operating in your home directory on your Mac, using Unix commands. Keep using the Terminal program to complete the remaining steps.

  3. Install an .Xdefaults file. Before doing this, save any existing .Xdefaults file by typing:

    mv .Xdefaults old.Xdefaults

    and hit Return. (I'll stop mentioning the Return key from now on; just press it after each command.) If the system responds cp: .Xdefaults: No such file or directory that means there was no such file, which is fine. If it doesn't respond at all, except by giving you a new prompt, that means it copied your old .Xdefaults settings file to a new file called old.Xdefaults in case you need it later. Now install the new .Xdefaults file by typing:

    curl -sRo .Xdefaults http://www.ssc.wisc.edu/~logan/settings/mac.Xdefaults

    This will copy an .Xdefaults file created by John Logan and made available on the SSCC web server to your system. To verify it was installed, type ls -l .Xdefaults, which will show the file in your directory.

  4. Install a new .xinitrc settings file the same way. First, type:

    mv .xinitrc old.xinitrc

    and then:

    curl -sRo .xinitrc http://www.ssc.wisc.edu/~logan/settings/mac.xinitrc

  5. Add a single, new line to the .cshrc file in your home directory. First, check that the file is there by typing ls -l .cshrc. Then save a copy:

    cp .cshrc old.cshrc

    The new line that needs to go into the existing .cshrc file is this:

    stty erase '^?'

    It can go just about anywhere in the file, so if you are using an editor for this project, type it in, on its own line. In fact, it will be okay if the new line is added as the last line in this file, so you can add it there, without using an editor, by typing:

    curl http://www.ssc.wisc.edu/~logan/settings/mac.cshrcline >> .cshrc

    Make sure you use two right-carets (greater-than symbols), as shown.

  6. Now log onto your Linux account, still inside Terminal, by typing

    ssh {username}@hal.ssc.wisc.edu

    Use your own SSCC username instead of {username}, of course. Then save any existing .emacs file by typing:

    mv .emacs old.emacs

    and install the new one like this:

    curl -sRo .emacs http://www.ssc.wisc.edu/~logan/settings/linux.emacs

  7. You have completed the installation. Log out of the Linux account session, and quit the Terminal program.

Running Linux Programs

To run Linux programs (with or without X-window features) open X11 on the Mac and log in using the -X flag like this:

ssh -X {yourusername}@{server}.ssc.wisc.edu

Replace {yourusername} with your own user name on the SSCC system. Replace {server} with either kite or hal, the SSCC's public Linux servers. You will find yourself in a text-based terminal window similar to the one Mac's Terminal program provides.

To operate Stata in X-window mode, type xstata at the prompt. A new window will open with an interactive Stata session.

To operate emacs in X-window mode, including color coding for various statistics and programming languages, type emacs. To operate emacs in text-based mode, but still with color coding, type emacs -nw (think "no window"). This starts up faster, with a clearer type face.

Copying and Pasting

Copying and pasting is done differently in X11 Windows than in Mac windows. (X11's copy and paste features come from an industry standard called X11R6, or X Windows.) Only text can be copied and pasted within X11 windows, or between X11 and Mac windows.

  1. To copy and paste text within an X11 window, position the text cursor (not the mouse cursor) where you want the text to be pasted. Then use the mouse to highlight the text to be copied. Don't move the mouse, but leave it positioned so the desired text is highlighted. Then hold down the option key, and click the mouse button. The text is copied and inserted where the text cursor was positioned.

  2. To copy text from an X11 window and paste it into a Mac window, use the mouse to highlight the desired text, then copy it with Cmd-C, the usual Mac copy command (or use the Mac's menu). Then move to the Mac window, click the mouse on the desired destination location, and use Cmd-V, the usual Mac paste command, to paste the text.

  3. To copy text from a Mac window and paste it into an X11 window, select the desired text and copy it with Cmd-C. Then move to the X11 window, position the text (not mouse) cursor where you want the text pasted, hold down the option key, and click the mouse button.

Moving Statistical Graphics to the Mac

As mentioned in the previous section, only text can be copied and pasted between X11 and Mac windows. However, for draft manuscripts, it is convenient to use the Grab utility program on the Mac to capture screen images of graphs in X11 windows and then paste them into Mac documents in the usual way. (The Grab program should be in the Utilities folder inside the main Applications folder.)

For publication-quality graphics, use the features of the statistical program (e.g., Stata, SAS) to save graphics in pdf, (encapsulated) postscript, jpeg, tiff, gif, or another high resolution format, then move the graphics file to the Mac. Open the file in the Mac's Preview program and then copy and paste the image into a word-processor document, preserving its high resolution. Alternatively, use your word processor's features to insert the high-resolution file directly.

Graphic and other files can be moved from Linux to the Mac in several ways.

  1. If you are on the same local network with the Linux machine (as you are when in the Social Science Building) you can mount the Linux disk on your Mac desktop, and then drag files back and forth between Linux and Mac folders. Choose Connect to Server under the Go menu on the Mac's desktop to mount the Linux disk. Type in smb://sscunix/{yourusername}/ in the Server Address box, and hit the Return key.
  2. If you are not on the same local network, you can establish a Virtual Private Network (VPN) connection from your Mac and then follow the procedure just given. Contact the SSCC Help Desk for assistance.

  3. You can also transfer files with the (Mac) Unix commands ftp or curl. See Using SFTP for details.

Special Note on Stata

Experience has shown that Stata for Linux and the ssh client included Mac OS 10.4 are not compatible. The solution is to use the ssh client from OS 10.3.9 or earlier. It can be installed along with the 10.4 version. Hopefully this problem will be fixed in future versions.

 

Thanks to John Logan for contributing this article.

Last Revised: 3/1/2006