To generate an SSH key pair, you can use the ssh-keygen command. Here’s how to do it:
-
Open your terminal.
-
Run the following command:
ssh-keygen -t rsa -b 4096This command specifies:
-t rsa: Use the RSA algorithm for key generation.-b 4096: Create a key with 4096 bits for strong security.
-
When prompted, you can:
- Enter a file path to save the key (press Enter to accept the default path
~/.ssh/id_rsa). - Enter a passphrase (you can leave this empty by pressing Enter twice).
- Enter a file path to save the key (press Enter to accept the default path
After running the command, you will see output indicating that your keys have been generated. The private key will be saved in the specified file (e.g., ~/.ssh/id_rsa), and the public key will be saved in the same location with a .pub extension (e.g., ~/.ssh/id_rsa.pub).
To view your public key, you can use:
cat ~/.ssh/id_rsa.pub
This will display your public key, which you can share with remote servers for authentication.
