Getting started with SSHThe following sections hope to provide enough information to setup a user new to ssh with the appropriate files necessary for accessing remote hosts in a secure manner. Contents
Intro to public key cryptographyPublic key cryptography uses a public key to encrypt data and a private key to decrypt it. The name public key comes from the fact that you can make the encryption key public without compromising the secrecy of the data or the decryption key. What this means is that it is safe to send your public key
(i.e. the contents of the To further protect your private key you should enter a passphrase to encrypt the key when it is stored in the filesystem. This will prevent people from using it even if the gain access to your files. Creating your authentication keyThe very first step is to use
Always, always, type in a good pass-phrase when prompted for one. It can be multiple words (i.e. spaces are just fine within the phrase), so you could choose a sentence that you can remember. Changing some of the words by misspelling them or by changing some of the letters into digits is highly recommended to increase the strength of your pass phrase. Here is a sample session, your input is in bold. Note that the pass-phrase is not echoed back as you type it.
csociety% ssh-keygen Initializing random number generator... Generating p: .++ (distance 6) Generating q: ........++ (distance 110) Computing the keys... Testing the keys... Key generation complete. Enter file in which to save the key ($HOME/.ssh/identity): [RETURN] Enter passphrase (empty for no passphrase): $av3 Th3 Tr33$ Enter same passphrase again: $sav3 Th3 Tr33$ Your identification has been saved in /home/sigos/.ssh/identity. Your public key is: 1024 37 [lots of numbers] sigos@csociety.purdue.edu Your public key has been saved in /home/sigos/.ssh/identity.pub If you have multiple accounts you might want to create a separate key on each of them. You may want to have have separate keys for
This allows you to limit access between these organizations, e.g. not allowing the university account to access your ISP account or the machines in the office. This enhances the overall security in the case any of authentication keys are compromised for some reason. Changing your pass-phraseYou can change the pass-phrase at any time by using the
csociety% ssh-keygen -p Enter file in which the key is ($HOME/.ssh/identity): [RETURN] Enter old passphrase: $sav3 Th3 Tr33$ Key has comment 'sigos@csociety.purdue.edu' Enter new passphrase (empty for no passphrase): Y0ur Pa$$phra$e H3r3 Enter same passphrase again: Y0ur Pa$$phra$e H3r3 Your identification has been saved with the new passphrase. The pass-phrases are not echoed as you type them. Authorizing accessTo allow access to a system for a given identity place the
public key in your Usually you will want to authorize access to the local system
using the local key (especially in an environment where multiple
systems share the same home directory e.g. using
csociety% cd ~/.ssh csociety% cp identity.pub authorized_keys You could now copy the Use a text editor to add more keys to the file. If you use
cut and paste to copy the key make sure each key entry is a
single line in the file. The keys to add are always
the public keys (from files with the NOTE: To gain access to restricted systems you
might need to send your public key in electronic mail
to the administrator of the system. Just include the contents of the
Directory and file permissionsIf access to the remote system is still denied you should check the permissions of the following files on it:
The permissions should allow writing only by you (the owner). This example shows the most relaxed permissions you could use. etla% cd etla% ls -ld . .ssh .ssh/authorized_keys drwxr-xr-x 36 sigos sigos 4096 Jul 25 02:24 . drwxr-xr-x 2 sigos sigos 512 Apr 10 02:30 .ssh -rw-r--r-- 1 sigos sigos 1674 Apr 10 02:29 .ssh/authorized_keys To make the remote system allow access you must change the permissions to disallow writing by others than the owner.
etla% cd etla% chmod go-w . .ssh .ssh/authorized_keys Remember to do this on all the systems you want to have access to. Logging into remote systemsTo establish an interactive connection to a remote system you
would use either the csociety% slogin etla Enter passphrase for RSA key 'sigos@csociety.purdue.edu': Y0ur Pa$$phra$e H3r3 Last login: Wed Oct 16 20:37:00 1996 from idefix [more output from the remote machine] etla% You can avoid the pass-phrase prompts by keeping the authentication keys in memory. You only need to type the pass-phrase when you add a key into memory. If your account name on the remote system differs from the one on
the local system (the system you are connecting from) you can use
the csociety% slogin -l oboyle gestalt.isca.uiowa.edu Last login: Sun Oct 13 14:55:17 1996 from csociety.ecn.purdue.edu [more output from the remote machine] gestalt% You can change the default remote account name by creating a configuration file entry for the host. Keeping authentication keys in memoryIf you frequently open connections to remote systems you can run
your session under the When you start csociety% ssh-agent $SHELL csociety% You will now need to add keys into memory to have them available for other commands. Running X on a local displayIf you have workstation where you start the X window system after
logging in you can have the whole windowing environment benefit
from the keys in memory. The X window system is normally started
with csociety% ssh-agent startx & If your workstation has virtual consoles it is good to put the X window system in the background so the current virtual console can still be used for more commands if necessary. It won't hurt to background the command even without virtual consoles. NOTE: Your system might have a non-standard
way of starting the X window system. Replace
Running X with an xdm sessionIf you use an X-terminal or your workstation is running xdm you
need to arrange for the clients to run under
An example #!/bin/sh if [ -d $HOME/.ssh ] then EXEC="exec ssh-agent" else EXEC="exec" fi if [ -x $HOME/.xinitrc ] then $EXEC $HOME/.xinitrc else $EXEC xterm -geometry 80x24+0-60 -ls fi Make sure the files are executable. The following command will change the permissions suitably. csociety% chmod u+x ~/.xinitrc ~/.xsession What you have now done is made ssh-agent your initial process in your X session. After you use ssh-add to give your identity to the agent, we can seamlessly ssh over to all hosts who know who we are, should our destination be 'ssh-friendly' X11 forwarding is automagically set up for you. NOTE: If you are using an X-terminal keep in mind that your session is most likely not secure. Usually anything you type can be captured on the local area network you are connected to. Managing keys in memoryBefore your connections can be authenticated without prompts for
a pass-phrase you have to use csociety% ssh-add Need passphrase for /home/sigos/.ssh/identity (sigos@csociety.purdue.edu). Enter passphrase: Y0ur Pa$$phra$e H3r3 Identity added: /home/sigos/.ssh/identity (sigos@csociety.purdue.edu)If you are in X, ssh-add will pop up a nice window if your output isn't attached to a terminal. Place this line in you .xinitrc file. ## Get my passphrase for ssh'ing around.
Usual keywords include (defaults in parenthesis):
Here is an example Host *purdue.edu
User sigos
Compression no
Host *uiowa.edu
FallBackToRsh no
Host *
Compression yes
CompressionLevel 9
FallBackToRsh yes
KeepAlive no
Options are accumulated over entries, but a more specific entry will
override a less specific one. E.g. in the above compression will not
be used for hosts that match For a complete list of options please refer to the manual pages of
both Sources of more information
Some people like to create functions (these happen to be in ksh) to manage
ssh. For example, if one was behind a firewall that didn't allow servers
to connect on privileged ports, you could use the For more tricks for using ssh behind a firewall, drop me a note. ssh () {
/usr/bin/ssh "$@"
}
sterm () {
ssh -f "$1" "exec /usr/X11/bin/xterm -T '$1' -n '$1'"
}
|
| Original document by Kimmo Suominen <kim@tac.nyc.ny.us> | Improvements and updates by Todd O'Boyle <oboyle@cs.purdue.edu> |