1. Generate a New SSH Key Pair
-t rsa
specifies the type of key (RSA in this case).-b 4096
sets the number of bits for the key length (4096 is more secure).-C "HSingh@MindTelligent.com"
adds a comment (usually your email) to help identify the key.
2. Save the Key Files
- You will be prompted to enter a file name and location to save the key pair:
- Press Enter to save it in the default location (
~/.ssh/id_rsa
). - Or specify a custom path if you want multiple keys.
- Press Enter to save it in the default location (
3. Set a Passphrase (Optional)
You will be asked:
- Enter a passphrase for extra security, or press Enter for no passphrase.
4. View the Public Key
This will display the public key, which you can copy to add to remote servers or platforms like GitHub, GitLab, or AWS.
5. Add Key to SSH Agent (Optional for Convenience)
6. Add SSH Key to Git Hosting Provider
- GitHub: Go to Settings → SSH and GPG keys → New SSH Key and paste the contents of your public key:
- GitLab/Bitbucket: Follow similar steps under SSH Keys settings.
7. Test SSH Connection
Test the SSH connection to your hosting provider:
- For GitHub:
- For GitLab:
You should see a success message, e.g.:
8. Clone Repository Using SSH
Copy the SSH URL of the repository from the hosting provider. It looks like:
Then, clone it: