Generating Secure SSH Keys with ssh-keygen
The ssh-keygen
command is the primary tool used to generate SSH keys on Linux systems. This command allows you to create a pair of cryptographic keys, including the public key and the private key.
Generating SSH Keys
To generate a new set of SSH keys, follow these steps:
-
Open a terminal on your Ubuntu 22.04 system.
-
Run the following command to generate a new SSH key pair:
ssh-keygen -a 100 -t ed25519
The -a 100
option specifies the number of KDF (key derivation function) rounds, which increases the security of the key. The -t ed25519
option selects the Ed25519 algorithm for the key type, which is considered more secure than the older RSA algorithm.
-
When prompted, enter a file path to save the key pair (e.g., ~/.ssh/id_ed25519
) and optionally set a passphrase to protect the private key.
The ssh-keygen
command will generate the public and private keys, and store them in the specified file location.
Key Fingerprint and Randomart Image
After generating the keys, you can view the fingerprint and the randomart image of the public key using the following commands:
ssh-keygen -lf ~/.ssh/id_ed25519.pub
ssh-keygen -Bf ~/.ssh/id_ed25519.pub
The fingerprint and randomart image can be used to verify the integrity and uniqueness of the public key.
Key Algorithm and Bit Length
When generating SSH keys, you can choose from different algorithms and bit lengths. The recommended choices are:
- RSA: 2048 or 4096 bits
- ECDSA: 256, 384, or 521 bits
- ED25519: 256 bits
The ED25519 algorithm is generally considered the most secure and efficient choice for SSH keys.