How to Generate SSH Keys for GitHub
2 min readFeb 27, 2023
No more confusing tutorials! In this article, let’s keep it simple. You’ll generate a SSH public key to be used with Git using ssh-keygen and learn how to apply it to your GitHub account.
Generate a SSH key for Git
At the bottom of this section is a sample terminal with all the inputs and outputs
- Go to your .ssh directory (this is usually found in the home folder)
- Run ssh-keygen
- When asked ‘Enter file in which to save the key’, press enter to use default values
- When asked ‘Enter passphrase (empty for no passphrase)’, enter a password (Note: Do NOT leave the password empty. Passwords are case-sensitive)
- You will now have two generated keys, a private key ‘id_rsa’ and a public key ‘id_rsa.pub’ (Note: NEVER open your private key! If you open your private key, it will get loaded to memory which opens you up to security vulnerabilities)
- Ensure you have the right file permissions for your SSH keys! (Note: Do a quick search online for the most up-to-date permission recommendations)
- Open the file ‘id_rsa.pub’ containing your public SSH key and copy all the contents of the file to your clipboard
- Done! You now have a public SSH key for Git (and other things)!
# Terminal example
ssh-keygen
Enter file in which to save the key (...): '<Press Enter>'
Enter passphrase (empty for no passphrase): '<Enter your password>'
Enter same passphrase again: '<Re-enter your password>'
Your identification has been saved in (...)/.ssh/id_rsa
Your public key has been saved in (...)/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:(... ...)
The keys randomart image is:
+---[RSA 3072]----+
| (...) |
+----[SHA256]-----+
'<Open your id_rsa.pub file>'
'<Copy all the contents of the file>'
'File contents sample: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB... (...username)'
Adding a new SSH key to your GitHub account (Optional)
In this section you will add the generated SSH key to GitHub and run the command ‘git clone’ to test it
- In the upper-right corner, click your profile photo and open ‘Settings’
- Under the ‘Access’ section of the sidebar, open ‘SSH and GPG keys’
- Click ‘new SSH key’
- Add a title and select ‘Authentication Key’ under the ‘Key Type’ field
- Paste your public key into the ‘Key’ field and click ‘add SSH key’
- Go to your desired GitHub repo and clone using SSH
- When prompted for your SSH password enter the password you entered in step 4 in the last section
- Done! Now you have SSH set up with GitHub!
Feel free to leave a response if you run into any issues or something is unclear. Happy Coding and God Bless!