Skip to content
Docs

Create an RSA or SSH key pair

Learn how to create an RSA or SSH key pair

View as Markdown
On this page· 5 sections

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:

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

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

    Shell
    cat private_key.pem
  4. View the Public Key:

    Shell
    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:

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

    Shell
    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