CS50 Outside of the Science Center -- Microsoft Windows
Computer Science 50
Fall 2006
February 3, 2008
This guide is about setting up your machine(s) outside of the Science
Center so that you can work on your CS50 assignments. You are not
required to setup any of your home machines to work on
assignments; you are always welcome and encouraged to use the Science
Center machines.
In assignment 1, you were introduced to the Linux machines at the
Science Center. Those machines are a part of the larger computer
setup in the Science Center referred to as the NICE environment (The
name NICE stands for New Instructional Computing Environment).
Although you can't log in remotely to those workstations, there are
Linux servers in the NICE environment that you can log into without
having to go to the Science Center. They run the same software as the
workstations, and you have the same home directory when you log into
them.
This guide will help you setup a SSH (Secure SHell) client to
connect to the NICE linux servers. These clients only give you a
simple command line terminal interface to the server. This guide
will also help you set up the X windows system (the graphical user
interface system for Linux) so you get a good user interface.
To log in to a NICE Linux server, you make an SSH connection to
nice.harvard.edu.
SSH is a secure communication protocol. Mac OS X and Linux machines
normally include an implementation of SSH that can be used from the
command line. In a terminal window on your personal machine, you
issue an SSH command that connects to the remote server. After you
supply your password, it leaves you at a command prompt from the
server machine. So SSH effectively turns your local terminal into a
remote terminal of the server, until you choose to log out of the
server.
Windows users usually obtain SSH by installing a terminal emulator
such as SecureCRT or PuTTY. You launch one of these applications for
the express purpose of creating a command window that's securely
connected to the remote server. But the net effect is the same as in
the Mac OS X/Linux case: you end up with a command-line interface to
the remote server, not a GUI.
So how can you benefit from the GUI features of an application like
Emacs when you're connecting remotely from your own PC?
It turns out that most implementations of SSH provide support for the
open-source window system called X, which is the native window system of
Linux and UNIX. While it has much in common with other window systems, X
is unusual in that its implementation is distributed. That means
that every time an X-based program like Emacs changes the user's display
or receives input from the keyboard, it uses the Internet to transmit the
information. As a result, the computer controlling the display, mouse, and
keyboard can be different from the computer running the X-based application
(such as Emacs), as long as they are both on the Internet and they both
support X.
When you use a Linux workstation in the Science Center, you won't
normally take advantage of the distributed nature of its window system,
because your GUI-based applications will be running on the same machine
that's managing the display, mouse, and keyboard.
But if your personal computer supports X, it can handle the graphical user
interface for applications that are actually running on a remote machine
that you have connected to via SSH. So you can make an SSH connection
to one of the NICE servers, start Emacs on that server, and it will
create a new X window on your own machine. Apart form its border
decorations, that window looks just like it would if you were at a
Linux workstation in the Science Center. And you can control it just
as conveniently with your mouse and keyboard.
We're about to explain how to make your computer support X windows in
this way. But first, a bit of lore and jargon.
The terminology of X involves a confusing reversal. Normally when
centralized computers are shared by distributed machines that act as
terminals for users, the central machines are called servers and the
terminal machines (and/or the programs on them that talk to the servers)
are called clients. But with X, the ``server'' is the program
closest to the display, keyboard, and mouse. It's the program at the
terminal that actually draws on the screen, tracks the mouse, and reads
input from the keyboard. The X ``client'' is a program such as Emacs that wants to have windows in which to interact. So the confusing
reversal, when you're logged in remotely, is that X clients run on the
server host (like nice.harvard.edu) and X servers run on client machines, like your own
PC.
To connect to one of the NICE servers, you must use SSH, the secure
connection protocol. The most obvious use of the SSH connection is to let
you type commands to the remote computer and see the results that it puts
out. But the same secure connection can also carry the messages used by
the X window system to control windows on your screen or read input from
your mouse and keyboard. If you configure it to do so, SSH makes X clients
like Emacs think that there is an X server on the same machine that they
are running on, and it also makes the X server on your PC think that its
remote clients like Emacs are actually local. (You may see this called
tunneling or port forwarding. After you learn about
networking later in the term, it will make more sense.) This arrangement
means that you can tell your X server only to accept ``local'' connection
requests. Requests that come through the SSH tunnel from your remote X
client will be accepted, since they appear to be local. But any other X
connections will be rejected, which is a good security feature.
By default, forwarding of X connections through SSH is not turned
on. To be sure that it's enabled when you need it, you can change
your personal SSH configuration. Here's a series of commands to do
that when you're logged into fas.harvard.edu or nice.harvard.edu:
mkdir -p
/.ssh
chmod go-rwx
/.ssh
cd
/.ssh
touch config
echo "ForwardX11 yes" » config
The mkdir above makes sure that you have a .ssh
directory in your home directory. Then the chmod command
makes sure that no one but you can read or write that directory. The
touch command makes sure that a file called config
exists under
/.ssh. And the echo command adds
this line to the end of that file:
ForwardX11 yes
Of course, if you'd rather just use an editor to make sure that
/.ssh/config exists and contains the line above, that's fine
too. But remember to use chmod to restrict access to the
config file.
No matter how you make your SSH connection to nice.harvard.edu, there's a simple way
to tell whether it's capable of supporting X windows. Type the command
echo $DISPLAY at the shell prompt from the
remote machine. The response should look like localhost:
.0,
where
is a two- or three-digit number. SSH should have set
DISPLAY automatically to this value. When an X client like
Emacs uses this setting of DISPLAY to contact its X server,
the messages it sends are piped through the secure SSH tunnel to
your terminal.
If the DISPLAY value is something else, then your current shell
initialization may be setting DISPLAY explicitly, rather than
allowing it to be set by SSH. Use an editor to inspect the files
/.login and
/.cshrc, and eliminate
commands that set DISPLAY.
If your personal machine runs Microsoft Windows, you need to install
third-party packages for SSH and for the X window system.
You've probably already installed an SSH-based terminal emulator called
SecureCRT that FAS makes available on its software download
page.
We'll first describe how to add a SecureCRT ``session'' for connecting to
nice.harvard.edu.
Then we'll show how to add an X server that can work together with
SecureCRT to give you GUI control of Emacs and other X-client
applications.
SecureCRT comes preconfigured with sessions for connecting to
Harvard destinations such as nice.fas.harvard.edu (which is
equivalent to nice.harvard.edu). A session customizes SecureCRT for a particular
remote host. There's a button for starting each of the configured sessions
in the Connect dialog box that (by default) comes up when you
launch SecureCRT.
Unfortunately, the preconfigured sessions need some tweaking for use with X
windows in general and Emacs in particular. Rather than changing the
nice.fas.harvard.edu session, we recommend that you modify your
default-session settings and apply the changes to all existing sessions.
That way, SecureCRT will behave consistently no matter which remote host
you connect to.
Here are the steps for configuring the default settings for SecureCRT
version 5 or later and applying the changes to existing sessions.
- Start SecureCRT. If the Connect dialog box pops up, close it.
Then choose Options
Global
Options... to bring up a window with a Category tree on the
left and configurable options on the right. In the steps below,
you'll set your default session options and possibly change the
default colors used.
- Choose the Default Session subcategory under
General, and click on the Edit Default Settings...
button. That brings up a new category-tree window for session options.
- Select SSH2 under the Connection category, and
type your FAS user name in the Username field.
- Click on the Remote/X11 category under Connection
Port Forwarding. Check the box that says
Forward X11 Packets.
- Click on the the Emulation subcategory of
Terminal, and choose Linux as
the terminal type. (That should automatically check the
box for ANSI Color, which allows applications like
Emacs to control text colors.) At the bottom of the same
screen, change the Scrollback buffer size to
32000. (That's how many lines will be saved for
scrolling back.)
- Click on Emacs under Emulation, and check the
box that says Use ALT as meta key.
- Click on Mapped Keys and then check Backspace
sends delete.
- Under the Appearance category, don't bother changing the
Current color scheme; it has no effect when ANSI color
control is turned on. But pick a font that suits you. In the
Cursor box at the bottom of the window, you can pick a
cursor color if you wish.
- Click OK to return to the global options window, clicking
Yes when you're asked whether to apply your changes to
all sessions.
- Select the Terminal category. Decide whether you want
selecting text with the mouse to automatically copy it into the
clipboard, and whether clicking with your middle mouse button should
automatically paste text from the clipboard. If so, check the
corresponding boxes under Mouse.
- Under the Appearance subcategory of Terminal,
select ANSI Color. This allows
you to adjust the color palette for normal text and bold text.
You don't need to change these settings unless you want to.
They only affect the SecureCRT terminal window, not the X applications
that you will start from it. But the default colors for normal text
look a bit dim and muddy. If you want to brighten things up, you
might swap the normal and bold versions of each hue except black.
- Click OK in the Global Options window to close it,
then use Options
Save Settings
Now... to be sure your new options are saved.
- Again from the menu bar, use File
Connect... to bring up the Connect dialog box.
Try out your new session settings by double clicking on
nice.fas.harvard.edu. You may see a New Host Key dialog
box. Click Accept & Save, then finish logging in. Try typing
the command hostname, followed by Enter. The server
should print its own name as ice
, for some digit
.
Next, issue the command echo $DISPLAY to
verify that the value is localhost:
.0, where
is a two- or
three-digit number. If so, proceed to the next paragraph and
install the X server. If SecureCRT is not working as expected, bring up
the Connect dialog again, select nice.fas.harvard.edu
and click on the Properties icon, fourth from the right in the
task bar of that dialog box. Check the session options against the
instructions above to be sure everything has been set and saved correctly.
- Navigate your way to: http://sourceforge.net/project/showfiles.php?group_id=156984
- From that page you will want to download to your computer both Xming (latest stable release 6.9.0.31),
and the Xming fonts package (latest stable release 7.3.0.11).
- After both are downloaded to your computer, double-click them to
install them on your computer. The process for this is very
self-explanatory.
- Now you will want to configure your SecureCRT session to interact using X
windows. Open up SecureCRT, but do not connect. Click on the "New Session" button.
(the third button from the left)
- Now to configure the session. You will want to use protocol SSH2, as should
be displayed. Click "Next".
- For hostname, type in "nice.fas.harvard.edu". Leave the port alone and it's
up to you whether or not you want to leave the Username blank (I normally have this
field filled in for me, but that's just me...)
- Name the session whatever you want. Click "Finish".
- At this point you should be returned to the list of session options. Choose
your session but don't connect yet. Instead click the "Properties" button (fourth
from the right).
- On the left, click on "Remote/X11" and check the box labelled "Forward X11
packets". For convenience, you may also want to click on the "Mapped Keys" tab
and set "Backspace sends Delete". (I recommend this as I find it annoying otherwise,
but this second option is also totally personal). From here you can also configure
your terminal set up (e.g. mine is set up with a red background with white font,
instead of the standard black on white). When you are done configuring, click "Ok".
- Close SecureCRT now, and run Xming. The Xming icon should appear in your
Taskbar, meaning Xming is running, and waiting.
- Reopen SecureCRT and begin your session using the session you just created.
At the prompt, run "xclock". A small clock in an X window should appear on your
screen. If so, you've got X windows!
Now suppose that you have a terminal window connected to a nice.harvard.edu server,
and that your $DISPLAY variable is correctly set. To start
Emacs, putting it into the background so that you can keep using
your terminal, type
emacs &
Of course, there will be times when you want to run Emacs, but X isn't
available. In that case, you start Emacs without putting it into
the background (no & on the command line). If X is
available (so your $DISPLAY variable is set), but
you want to use Emacs in non-X mode anyway, add -nw as a
command-line option:
emacs -nw
In non-X mode, you'll have to experiment to find out which keys work
as they do under X and which don't. It varies from terminal emulator
to terminal emulator. There's a way to get everything done, but it
may sometimes be inconvenient. The ``GNU Emacs Reference Card'' can
be used as a survival aid. Except for the strictly mouse-related
commands, it usually shows at least one key sequence per command that
will work on almost any terminal.
When configured properly, the SecureCRT and PuTTY terminal emulators
provide surprisingly good windows in which to run Emacs.
But, Emacs is much nicer to use under X.
Footnotes
- ...nice.harvard.edu.
![[*]](/usr/share/latex2html/icons/footnote.png)
- When logging in remotely to work on CS50, always use nice.harvard.edu.
You shouldn't use ice.harvard.edu or fas.harvard.edu. Since the actual name of the host
that you reach by connecting to nice.harvard.edu is not nice, but
ice
(e.g., ice2), you might think that
ice.harvard.edu is a synonym for nice.harvard.edu. It's not. It's the
generic name for connecting to a different kind of computer, running a
different operating system. The machines that you reach when you
connect to fas.harvard.edu do have the right hardware and operating
system, but they lack some of the software that you will need, such as
Emacs for X windows. They're just not nice.
- ...
![[*]](/usr/share/latex2html/icons/footnote.png)
- http://www.fas.harvard.edu/cgi-bin/software/download.pl
- ...nice.harvard.edu.
![[*]](/usr/share/latex2html/icons/footnote.png)
- PuTTY
(http://www.chiark.greenend.org.uk/~sgtatham/putty/) is
another popular terminal emulator that implements SSH. It's free, and
it includes all of the features that you'll need for work in CS50. If
SecureCRT bores or bothers you, check out PuTTY.
- ...
![[*]](/usr/share/latex2html/icons/footnote.png)
- If your SecureCRT installation is older than version 5, these
instructions won't fit it. Update to the version offered at
http://www.fas.harvard.edu/cgi-bin/software/download.pl.
- ... type
![[*]](/usr/share/latex2html/icons/footnote.png)
- Remember that you should kill all background processes before
logging out. To remind you, and give you a chance to exit Emacs gracefully, the
lib50/usr/cs50.logout script emits the
message
Waiting for background jobs to be terminated...
and then waits until all background processes have finished.
CS51 Course Library
2008-02-03