System Administration: Creating a Public/Private Key Pair

The standard procedure for creating a Secure Shell public/private key pair for UNIX-based systems (including Linux and macOS) follows. For information on additional options, see ssh-keygen.

  1. - Open your favourite terminal application
  2. - Run the key generation program:
    ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key(/home/user/.ssh/id_rsa):
  3. - Enter the path that you want to store the file that will hold the key:
    By default, the file name id_rsa, which represents an RSA v2 key (as specified in the command above), appears in parentheses.
    You can select this file by pressing Return. Or, you can type an alternative filename.
  4. - Enter a passphrase that will need to be entered every time you want to use your key. If you're going to use the key for scripting purposes, just press Return to use a blank passphrase:
    Enter passphrase(empty for no passphrase): 
  5. - Re-enter the passphrase to confirm it:
    Enter same passphrase again:
    Your identification has been saved in /home/user/.ssh/id_rsa.
    Your public key has been saved in /home/user/.ssh/
    The key fingerprint is:
    0a:1b:2c:3d:4e:5f:60:71:82:93:a4:b5:c6:d7:e8:f9 user@hostname
  6. - The public key name is created automatically and the string .pub is appended to the private key name and stored in the location you provided above. If, however, you chose the default, the file will be stored in your home directory under a hidden folder called .ssh.

If, however, you are using Windows, you can either go through the rigmarole of installing Linux for Windows, or you can create your public/private key pair using the following instructions based on PuTTY. PuTTY is an SSH client for Windows. It comes with a utility program called PuTTYgen which you can use to generate SSH key pairs.

You can download the PuTTY installer from Once downloaded and installed:

  1. - Open the PuTTYgen utility (Start Menu => All Programs => PuTTY => PuTTYgen):
    PuTTY key generator in Windows
  2. - Make sure that RSA is selected and press Generate.
  3. - Save your public and private keys to your computer.

Now that you have created your key pair, the public key can be shared or uploaded anywhere, but your private key should only be stored on personal devices that you and only you control.

Share :