6.2. Creating an IdentityMost SSH implementations include a program for creating key pairs. We will cover ssh-keygen from SSH1, SSH2, and OpenSSH.
6.2.1. Generating RSA Keys for SSH1SSH1 and its derivatives use the program ssh-keygen1 to create key pairs. [Section 2.4.2, "Generating Key Pairs with ssh-keygen"] The program might also be called ssh-keygen, depending on how SSH1 was installed. Let's go into more detail about this program than we have before. Appendix B, "SSH Quick Reference" summarizes the ssh-keygen options. ssh-keygen1 can create new keys or modify existing keys. When creating a new key, you may indicate the following with command-line options:
You might use this technique to automate generation of a large number of keys for some purpose. Use it carefully, though, on a secure machine. The password on the command line is probably visible to other users on the same Unix machine via ps or similar programs, and if you're scripting with this technique, obviously the passphrases shouldn't be kept in files for long. In addition to creating keys, ssh-keygen1 can modify existing keys in the following ways:$ ssh-keygen1 -f mykey -N secretword
WARNING: Before using any option that places your passphrase on the shell command line, such as -N or -P, carefully consider the security implications. Because the passphrase appears on your screen, it may be visible to onlookers, and while running, it may be visible in the machine's process list. Because it is on the command line, it is visible to other users on the same host using the ps command. In addition, if your shell creates history files of the commands you type, the passphrase is inserted into a history file where it can be read by a third party. Also, if you think have a good reason to just type Return and give your key no passphrase, think again. Doing that is essentially equivalent to putting your password in a file in your home directory named MY-PASSWORD.PLEASE-STEAL-ME. If you don't want to have to type a passphrase, the right thing to do is to use ssh-agent, trusted-host authentication, or Kerberos. There are very limited circumstances having to do with unattended usage (e.g., cron jobs) where a plaintext, passphrase-less client key might be acceptable. [Section 11.1, "Unattended SSH: Batch or cron Jobs"]
6.2.2. Generating RSA/DSA Keys for SSH2SSH2 and its derivatives use the cleverly named program ssh-keygen2 to create key pairs. The program might also be called ssh-keygen, depending on how SSH2 was installed. As with ssh-keygen1, you can create new keys or modify existing ones; however, the command-line options are significantly different. ssh-keygen2 also has a few other options for printing diagnostics. When creating a new key, you may choose the name of the private key file to be generated, by specifying the name at the end of the command line:
The name is relative to your current directory, and as usual, the public key file is named after the private one with .pub appended. If you omit this option, the key is saved in the directory ~/.ssh2, in a file whose name indicates the encryption algorithm and number of bits. An example is id_dsa_1024_a, which was generated by the DSA algorithm with 1024 bits. You also may indicate the following with command-line options:$ ssh-keygen2 mykey creates mykey and mykey.pub
$ ssh-keygen2 -r I am stirring the random pool. blah blah blah ^D Stirred in 46 bytes.
6.2.3. Generating RSA/DSA Keys for OpenSSHOpenSSH's ssh-keygen program supports all the same features and options of its SSH1 counterpart. It also adds the capability to generate DSA keys for SSH-2 connections and a few more options:
6.2.4. Selecting a PassphraseChoose your passphrases carefully. Make them at least 10 characters long, containing a mix of uppercase and lowercase letters, digits, and nonalphanumeric symbols. At the same time, you want the passphrase to be easy to remember, but hard for others to guess. Don't use your name, username, phone number, or other easily guessed information in the passphrase. Coming up with an effective passphrase can be a chore, but the added security is worth it. If you forget a passphrase, you are out of luck: the corresponding SSH private key becomes unusable because you can't decrypt it. The same encryption that makes SSH so secure also makes passphrases impossible to recover. You have to abandon your SSH key, generate a new one, and choose a new passphrase for it. You must also install the new public key on every machine that had your original.
Copyright © 2002 O'Reilly & Associates. All rights reserved.