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
-
Generate the Private Key:
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
-
Extract the Public Key:
openssl rsa -pubout -in private_key.pem -out public_key.pem
-
View the Private Key:
cat private_key.pem
-
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
-
Generate the key pair:
ssh-keygen -t rsa -b 4096 -f figure_identity
-
View the Public key for pasting:
cat figure_identity.pub
Creating an SSH key pair in Windows using PuTTygen
- Download PuTTy Key Generator PuTTygen.exe file and run it.
- In the Key menu, select SSH-2 RSA Key
- In Parameters, select the RSA option.
- In Number of bits in generated key field, enter 4096
- In Actions, select Generate
- In the blank area under the progress bar, move your pointer in a random pattern to complete key pair generation.
- When generation completes, copy the contents of the Public key for pasting