Generate an SSH Key Pair on UNIX and UNIX-Like Platforms Using the ssh-keygen Utility

UNIX and UNIX-like platforms (including Solaris and Linux) include the ssh-keygen utility to generate SSH key pairs.

To generate an SSH key pair on UNIX and UNIX-like platforms using the ssh-keygen utility:
  1. Navigate to your home directory:
    $ cd $HOME
    
  2. Run the ssh-keygen utility, providing as filename your choice of file name for the private key:
    $ ssh-keygen -b 2048 -t rsa -f filename
    

    The ssh-keygen utility prompts you for a passphrase for the private key.

  3. Enter a passphrase for the private key, or press Enter to create a private key without a passphrase:
    Enter passphrase (empty for no passphrase): passphrase
    

    Note:

    While a passphrase is not required, you should specify one as a security measure to protect the private key from unauthorized use. When you specify a passphrase, a user must enter the passphrase every time the private key is used.

    The ssh-keygen utility prompts you to enter the passphrase again.

  4. Enter the passphrase again, or press Enter again to continue creating a private key without a passphrase:
    Enter the same passphrase again: passphrase
    
  5. The ssh-keygen utility displays a message indicating that the private key has been saved as filename and the public key has been saved as filename.pub. It also displays information about the key fingerprint and randomart image.