Configure SSH with GitHub (4096bit Key)

Hirosh Tharaka (BSc.Hons, CTFL)
3 min readMay 4, 2021

Most of the times, we tend to search this up when a new laptop is being given to you from your workplace. After facing the requirement for several times and have to go through several documentations, thought of drafting this in one sheet for the reference of anyone who needs it to resolve in one-go.

Step 1: Get the GitBash installed in your PC/Laptop

Step 2: Open the command line/terminal

Step 3: Set your username

git config --global user.name “FIRST_NAME LAST_NAME”

Step 4 : Set your email address

git config --global user.email “sample@example.com”

Step 5: Check for the updated username and email-address.

git config --list
Username and Email should display as above in your terminal/cmd

Step 6: Open GitBash

Step 7: Check if there's an SSH key which has been generated (to take a backup of it)

$ ls -la ~/.ssh/id_rsa*
If available, the files should display as above.

Step 8: Take a backup of the existing SSH key pair (id_rsa/id_rsa.pub) before regenerating a new key-pair

# Make a copy of the old SSH private key 
$ cp ~/.ssh/id_rsa ~/.ssh/id_rsa.old
# Make a copy of the old SSH public key
$ cp ~/.ssh/id_rsa.pub ~/.ssh/id_rsa.pub.old

Step 9: Create/Generate a new 4096-bit key pair (private key and public key)

$ ssh-keygen -t rsa -b 4096 -C "sample@example.com"

Step 10: Enter a file in which you want to save your keys.
(You can press enter and the default ~/.ssh/id_rsa will be used.)

Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter-key]

Step 11: Enter a passphrase or your can keep it empty
(but it is not recommended to keep it empty)

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

Note: Just press enter-key without typing any key, if you need to keep the passphrase empty.

Step 12: Two new SSH key pair will be generated for the .ssh folder. (C:/Users/you/.ssh/id_rsa)

Step 13: Open the id_rsa.pub file from NPP ofr VSCode and copy the content of it.

Step 14: Navigate to the GitHub account > Settings > SSH and GPG Keys

Add New SSH Key page on GitHub (as of 2021-April)

Step 15: Click on ‘New SSH Key’

Step 16: Add a custom name for title (Tip : Better to add the clue/hint to your passphrase in your title, because this passphrase is easy to forget as not being used frequently)

Step 17: Paste the copied content on the Key section

Step 18: Click on ‘Add SSH Key’

Tadaaa!! Its Done!! Commit some files and push to the GitHub and verify if the data is being pushed. ;)

--

--