How to generate an RSA key pair
- Choose a key size. 3072 bits is the current recommendation; 2048 is the minimum still considered safe, and 4096 adds margin at the cost of speed.
- Optionally set a comment, usually your email or computer name, which is added to the SSH public key.
- Press Generate. You get an OpenSSH public key, the public key in PEM format, and the private key in PEM (PKCS#8) format.
- Download the private key as
id_rsainto your~/.sshfolder and runchmod 600 ~/.ssh/id_rsa. Add thessh-rsa …line to a server'sauthorized_keysor to GitHub, GitLab or your cloud provider.
About RSA keys
RSA is a public-key algorithm: the public key can be shared with anyone and is used to verify signatures or encrypt data, while only the matching private key can sign or decrypt. Keys are created here by your browser's Web Crypto API, which uses the operating system's cryptographic random number generator, with the standard public exponent 65537. The private key never leaves your device. The SHA-256 fingerprint matches what ssh-keygen -lf shows, so you can confirm a key was installed correctly.
The private key is not password protected. For daily use, add a passphrase with ssh-keygen -p -f ~/.ssh/id_rsa, which also converts it to OpenSSH's own format. For new SSH keys, Ed25519 (ssh-keygen -t ed25519) is shorter and faster, but RSA remains the most widely compatible choice for older servers, network devices, JWT signing (RS256), TLS testing and code signing. Treat any key generated on a shared or untrusted computer as compromised.
Is it safe to generate keys in a browser?
Yes, on a trusted device: Web Crypto uses the same secure random source as native tools, and nothing is uploaded. For production servers, many teams still prefer ssh-keygen on the machine itself.
Can I use the PEM key with OpenSSH?
Yes. OpenSSH reads PKCS#8 "BEGIN PRIVATE KEY" files. Set permissions to 600 first.
Which key size should I choose?
3072 bits for keys used beyond 2030, as NIST recommends. 2048 is fine for short-lived keys and old systems.