Ssh is a secure shell program. It is actually a family of programs (ssh, scp, sftp) that replaces the older and now deprecated rsh, rcp and ftp. In essence, the only difference between the ssh programs and the ones they replace is in how they handle passwords. Ssh never transmits passwords in the clear. There is a man page for ssh on most machines. However, like many man pages, it's mostly inscrutable and primarily useful for figuring out what to do if you already know what it says. This web page tries to make things a bit easier to understand by talking about how to use ssh, rather than how it works.
You might also want to check out this pdf file for a great high level overview of how ssh works, and some of its features.
There are two ways to uses ssh. You can enter your password every time you want to access a remote machine, or you can enter your password once when you login with an agent who will then field password requests on your behalf by ssh-enabled servers. To use the first option, you need do nothing. Simply use ssh, scp, or sftp.
The second option is much more convenient, but does require a few minutes to setup the very first time. The instructions below explain how to do this.
ssh-keygen -t rsa
ssh target mkdir .ssh
where target is the name of the target machine. Enter your password (NOT your passphrase, which you specified with keygen). Then, type
scp target ~/.ssh/id_rsa.pub target:.ssh/authorized_keys2
Again, enter your password.
If you already have a .ssh/authorized_keys2 on the target, type
cat ~/.ssh/id_rsa.pub | ssh target "cat >> ~/.ssh/authorized_keys2"
Enter your password when asked.
There are two options -- one that uses a native MAC OS X agent, and one that just uses Unix tricks. Read the description below for the Unix approach. If it seems to complex for you, pick up the native agent from here.
The Unix approach will have you use the file system to communicate the location of the agent and explicitly "grab" that information each time we start a shell. Here are the instructions for making this happen in such a way that you only have to enter your passphrase for the first terminal shell you create:
Here's how this works. When you login, you will automatically source the script sshlogin.cmds which will in turn run the program sshstart. This program will check to see whether you are already running a copy of ssh-agent (part of the ssh family). If not, sshstart will start up ssh-agent, which will ask you for your passphrase, and then save the agents TCP/IP address into the file ~/.ssh/sshagent.cmds. This file is sourced in order to set the location into shell variables (SSH_AGENT_PID and SSH_AUTH_SOCK). Once this is done, any ssh program you run from the shell you just started will "know" where to find the ssh-agent. At any time, you can run sshkill to terminate the agent, and sshstart to restart it.
Note that the passphrase you enter to shadd is NOT your local password, which is used to control access to the machine you are running on. The passphrase is used to PROTECT your private key, which is stored in the .ssh directory. There is no reason to make your login password the same as your passphrase, although it makes things easier to remember.
eval `ssh-agent`
ssh-agent
before you start up the window manager, and add
eval `ssh-agent -k
at the end.
Put the following line in a file called ~/.ssh/config:
ForwardX11 yes
Now, from within an xterminal, ssh over to the target. On the target, the DISPLAY variable will be set (oddly) to "localhost:11.0" (or some other small number). What's really happening is that the ssh daemon on the target machine (where localhost is implied), will act as an X11 proxy tunnel, forwarding your X11 traffic over an encrypted link back to the original machine.
NOTE that this also makes it possible to run X11 across a NAT or firewall. This is very useful for home use.
For example, suppose you have want to use IMAP from the road to connect your mail client to your mail server running on a departmental machine. Your "point of presence" though is blocked from sending traffic to the IMAP and SMTP ports on the mail server. You can set up an SSH tunnel to circumvent the restriction.
On the machine running the mail client, run:
ssh -N -L 9997:yourname.mail.cs.washington.edu:997 -L 9025:yourname.mail.cs.washington.edu:25 targethost&
where "yourname.mail.cs.washington.edu" is your IMAP/SMTP server, and "targethost" is a machine that is not blocked from communicating with the server.
Now, set up your mail client to send mail at localhost port 9025, and to get mail at localhost port 9997.
NOTE: I've not been able to get the IMAP port forwarding to actually work. Possibly due to it being IMAPS??
To enable ssh forwarding, add the line
ForwardAgent yes
to the file ~/.ssh/config
If it's still not working, then the target machine may not be running
a compatible version of the ssh daemon. I've never seen this happen
in the department, but if you are connecting an unmanaged machine, it's
conceivable. At this point, I suggest you consult the man page for
ssh for help in resolving this.
Copyright 2003 Brian Bershad