[Univ of Cambridge] [Dept of Engineering]

ssh (secure shell) - how to use it

How should I authenticate myself

The simplest use of slogin and friends will seem identical in terms of perceived behaviour to rlogin and equivalents, in that you will either be prompted for your normal password, or the server will honour an entry in your .rhosts file on the server machine.

You need do nothing other than type the appropriate command in order to use this authentication method.

You should be careful about using .rhosts to suppress the password check. Although ssh makes this much safer, it is still the case that you should only add sets of machines that are administratively similar and maintained to a similar level of security to your .rhosts file.

It is an extremely bad idea, except in very rare circumstances, to add machines that are on administratively separate networks to your .rhosts file

using RSA authentication

An alternative method of authentication is to use an RSA key. In order to do this, you will need to generate a key. You do this with the ssh-keygen utility. A typical interaction might involve (note use of <RTN> to indicate use of the return key):

prompt% ssh-keygen
Initializing random number generator...
Generating p: ........++ (distance 182)
Generating q: ............................++ (distance 434)
Computing the keys...
Testing the keys...
Key generation complete.
Enter file in which to save the key (/home/dir/user/.ssh/identity):<RTN>
Enter passphrase: <some random text>
Enter the same passphrase again: <some random text>
Your identification has been saved in /home/dir/user/.ssh/identity
Your public key is:
1024 35 133777033195454181308534301974704215516539776344994037802989908354767
14809022511208822265100038232396074598360105164668587433566772840306116723704
52235058852243181484380680715862992398347915669158374936097579417481571914065
09059282441280449801889096111489361541665530985707255386642739026912791701192
792431243 user@host
Your public key has been saved in /home/dir/user/.ssh/identity.pub

You should always use a good passphrase when you create your private key - this will protect against compromise of the machine on which you store it, or of the network across which the file containing the private key may be NFS exported. As a rough guide, a passphrase should be between 10 and 30 characters long, and not consist of a simple sentence, as English words in normal sentences only generate one or two bits of "entropy" in the resulting passphrase (ie the information content of each word is surprisingly low). On the other hand, it shouldn't be so random and unmemorable that you find you have to write it down.

In order to use your key, you need to make sure that any machine you wish to connect to knows the public half of the key. You can do this by copying the contents of the public key file (/home/dir/user/.ssh/identity.pub in the example above) to the file named $HOME/.ssh/authorized_keys (where $HOME is your home directory) in each case.

Once you've done all this, you will find that instead of the interaction that you're used to with slogin and friends, in which you were probably prompted for a password as:
user@host's password:
you will now get prompted as follows:
Enter passphrase for RSA key 'user@host':
and should then type in the passphrase that you used to encrypt the file containing your private authorization key when you ran ssh-keygen originally.

This doesn't seem to have gained us anything over using straight password authentication, but seems to require more typing of passwords/passphrases than rhosts with RSA host authentication, so why should we bother?

The reason to use RSA authentication is that we can set up an authentication agent to do all the hard work of sending RSA authorization keys for us, and save ourselves a lot of work without noticeable loss of security.

How do I use an authentication agent?

Ideally what we want is for every session we establish to be able to use the authentication agent, so we never have to bother with typing pass phrases. We just want to type a pass phrase once when we turn up at our computer ...

For the moment, assume that the intention is to sit down in front of a machine running X11, and for all the remote logins we run in various windows to be authenticated for us. There are two possible cases:

you start the X11 server yourself using xinit or startx
In this case, your window manager (and subsequently all the X11 programs such as xterm that you run from it) will be child processes (or descendants) of a process that runs the file $HOME/.xinitrc.
you log in to a terminal that's already running an X11 server
In this case, the terminal will initially have a window for you to type your login name and password into (ie it is running xdm, dtlogin or vuelogin. When you have logged in, it will run your window manager and any other X11 programs such as xterm as child processes (or descendants) of a process that runs the file $HOME/.xsession.
The simplest way of dealing with this is to put the line
eval `ssh-agent`
(note that those are back-quote symbols) at the beginning of both $HOME/.xinitrc and $HOME/.xsession files. You will also want to put the line
ssh-agent -k
(note that there are no back-quote symbols in this case) at the end of these files. If the last thing previously in these files was run with exec then you should remove that word (ie replace
exec fvwm
with
fvwm
This latter command will seek out any running ssh-agent process and kill it. Once our X11 session has shut down, we have no requirement for an authentication agent any more, and it is preferable (more secure) for it to no longer be active.

Note that we have set things up so that there is an authentication agent that any instances of slogin, ssh or scp called in that X11 session will know about and use, but we haven't told it any authentication keys. So sometime we will need, in any window we have available, to run the ssh-add command for any identities we wish to have automatically authenticated. Alternatively if you run ssh-add < /dev/null, it will run the program with an X11 interface that you can type into - this can usefully be integrated into your .xsession file.

Note also that if you leave your terminal unattended in this state (ie after you've used ssh-add), anyone wandering up to it will be able to log in to any of the machines that trust your authentication key. This is no more insecure than if you had a .rhosts file trusting the machine, but re-emphasises the need to be careful about leaving terminals unattended for any length of time.

How do I tunnel X11 through an ssh connection?

This should be a fairly simple section - if either slogin or ssh notice that the DISPLAY environment variable is set on the client side, they will automatically set up an X11 forwarding tunnel on the connection. Thus, all you should need to know is that, if your local session can start X11 programs successfully, and you run an ssh session to a remote machine using slogin or ssh, then you should be able to start X11 programs in the remote session and have them display locally without needing to do anything special at all.

However, if you want to know more detail as to how this works, they do several things to do this:

Using port forwarding in general

If you need to use this, you should only do so if you are capable of acquiring and understanding the documentation provided with the ssh package. Briefly, this facility has been disabled on CUED machines for operational reasons. However, providing care is taken and disruption is not caused, there is no reason for an individual not to run their own sshd configured to support port forwarding.

Using compression

There are several different questions to be answered here: In summary, there is no point in using compression unless you're on a slow link. It will be of benefit when transferring files that aren't already compressed, and may be of use when running remote X11 applications.

Debugging ssh

The simplest way of debugging ssh is to use the -v flag to get the client to indicate what it's doing. If you can't determine what is going wrong from this, you will either need expert assistance, or access to a ssh server that you can control and run in debugging mode.

When things go wrong ...


[Help]

Updated on 8th October, 1998
Patrick Gosling
jpmg@eng.cam.ac.uk