Skip to main content

Creating an RSA or SSH Key Pair

Generating an RSA key pair is essential for encrypting and decrypting sensitive data securely. This guide provides step-by-step instructions for generating an RSA key pair using the command line.

Creating an RSA Keypair

OpenSSL is a widely-used toolkit for the TLS and SSL protocols. It can also be used to generate RSA key pairs.

Creating an RSA Key Pair on the Command Line using OpenSSL

  1. Generate the Private Key:

    openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
  2. Extract the Public Key:

    openssl rsa -pubout -in private_key.pem -out public_key.pem
  3. View the Private Key:

    cat private_key.pem
  4. View the Public Key:

    cat public_key.pem

Creating an SSH Keypair

ssh-keygen is a tool for creating new authentication key pairs for SSH. Such key pairs are used for automating logins, single sign-on, and for authenticating hosts.

Creating an SSH key pair in Linux or macOS using ssh-keygen

  1. Generate the key pair:

    ssh-keygen -t rsa -b 4096 -f figure_identity
  2. View the Public key for pasting:

    cat figure_identity.pub

Creating an SSH key pair in Windows using PuTTygen

  1. Download PuTTy Key Generator PuTTygen.exe file and run it.
  2. In the Key menu, select SSH-2 RSA Key
  3. In Parameters, select the RSA option.
  4. In Number of bits in generated key field, enter 4096
  5. In Actions, select Generate
  6. In the blank area under the progress bar, move your pointer in a random pattern to complete key pair generation.
  7. When generation completes, copy the contents of the Public key for pasting