HMC Homepage      CS Home

Using SSH Tunnels

Topics:

Introduction to X Forwarding

One of the great things about modern computers is their ability to display windows and graphics. Wouldn't it be nice to be able to use this capability when logged in to a remote computer such as knuth? Fortunately you can! If your computer is running an X server, you should be able to easily and transparently run graphical programs on another computer and have them displayed on yours. Mac OSX runs an X server as do almost all Linux and Unix installations, so any of the computers in the CS terminal room or graphics lab will work with no additional setup. If you run Windows, or another operating system which does not use X natively, you will need to install an X server before you can display remote X programs locally. The most popular way to do this is to install cygwin.

Forwarding via SSH

Once you have a working X server you can use your familiar ssh client to forward the X traffic for you, and as a bonus, this also encrypts the traffic so no one can sniff it and find out things like usernames and passwords. Please note that you need to be running an xterm to do this, and the terminal usually used on the Macs in the CS labs is not an xterm. To open an xterm on those machines, open the finder, and click on Applications-> Utilities-> X11. To tell ssh to enable X forwarding, use the -X flag like this:

yourmachine% ssh -X userame@knuth.cs.hmc.edu

Now you should be connected to knuth via ssh and you can run your graphical programs on it. Test out the connection by typing the following:

knuth% xclock &

This command tells your shell to run the program xclock, which should display a small analogue clock on your desktop, and the ampersand (&) tells the shell to run the command in the background. This means you can still use that terminal for other things while the xclock program is running. If you do not see the xclock program running or get an error, something has gone wrong and your X forwarding is not set up properly. Try the following command:

knuth% echo $DISPLAY
localhost:XX.0

If the response is blank or something other than localhost:XX.X, you have not set it up properly. Some things that can go wrong are:

  • You used a lowercase "x" when running ssh (this explicitly disables X forwarding).
  • You are not running a terminal which supports X forwarding. On the Macs, make sure you are using the X11 application.
  • The program you are trying to run doesn't work with the setup creted by the -X flag; try -Y instead. This is less secure because the remote machine can spy on your activity (keylogging, etc), but some applications won't run with the tighter security.
  • You are not running an X server. If you run Windows, download and install cygwin if you need to have X forwarding.

If you have tried the above and it still doesn't work, send a message to staff and we will try to help you out.


Copyright (c) HMC Computer Science Department. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.''

HMC Computer Science Department
Contact Information
Last Modified Friday, 18-May-2007 14:39:08 PDT