Generating an SSH Key Pair
Linux/MacOS
Open a terminal and use the
ssh-keygen
utility to create your key. For a 2048-bit RSA key:For increased security, generate a 4096-bit RSA key:
Note: RSA is recommended over DSA because DSA keys are limited to 1024 bits.
When prompted, press Enter to use the default location (e.g.,
/home/your_username/.ssh/id_rsa
on Linux or/Users/your_username/.ssh/id_rsa
on Mac), or specify a custom location if needed (e.g., creating a second key).Enter a secure passphrase.
This passphrase is required to unlock your private key, adding an extra layer of security.
Without a passphrase, someone with your private key could access accounts tied to that key.
Confirm your passphrase when prompted.
Once complete,
ssh-keygen
will generate:A private key (e.g.,
id_rsa
) in the specified location.A public key (e.g.,
id_rsa.pub
) in the same location.
To use the public key:
For remote access, copy and paste the contents of the public key file into the
~/.ssh/authorized_keys
file on the server.To share with a team, send the public key (never share the private key).
Windows (Using PuTTY)
Download and start the puttygen.exe key generator.
In the Key section, select SSH-2 RSA, then click Generate.
Move your mouse randomly in the small window to generate entropy for the key pair.
Add a key comment to identify the key (useful when managing multiple keys).
Enter and confirm a passphrase to protect your key.
Save your keys:
Click Save private key to store your private key securely.
Click Save public key to save your public key.
To use the key with PuTTY:
Open PuTTY and navigate to Connection -> SSH -> Auth.
Browse and select your private key file.
Important Notes
Always keep your private key secure and never share it.
Use the public key to:
Add to
~/.ssh/authorized_keys
for servers you control.Share with teams or projects requiring access.
By following these steps, you ensure secure and efficient SSH access for your use cases.
Last updated