How to Generate SSH Keys for GitHub

Daniel Kondrashevich
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.

A pair of vintage grey keys on top of an open bible
Photo by Sixteen Miles Out on Unsplash

Generate a SSH key for Git

At the bottom of this section is a sample terminal with all the inputs and outputs

  1. Go to your .ssh directory (this is usually found in the home folder)
  2. Run ssh-keygen
  3. When asked ‘Enter file in which to save the key’, press enter to use default values
  4. When asked ‘Enter passphrase (empty for no passphrase)’, enter a password (Note: Do NOT leave the password empty. Passwords are case-sensitive)
  5. 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)
  6. 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)
  7. Open the file ‘id_rsa.pub’ containing your public SSH key and copy all the contents of the file to your clipboard
  8. 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

  1. In the upper-right corner, click your profile photo and open ‘Settings
  2. Under the ‘Access’ section of the sidebar, open ‘SSH and GPG keys
  3. Click ‘new SSH key
  4. Add a title and select ‘Authentication Key’ under the ‘Key Type’ field
  5. Paste your public key into the ‘Key’ field and click ‘add SSH key
  6. Go to your desired GitHub repo and clone using SSH
  7. When prompted for your SSH password enter the password you entered in step 4 in the last section
  8. 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!

--

--

Daniel Kondrashevich

Code-With Sr. CSA at Microsoft. "By the Grace of God, I am what I am"