Connecting to GitHub Using SSH

  • HTTPS (conventional way)
  • SSH
Image by Roman-Synkevych from Unsplash

Generating an SSH Key from our Command Line

It is important to note that in generating the SSH key, we can use different public key algorithms but we are going to look at RSA using the 4096-bit length key size and Ed25519 which is the most recommended public key available.

$ ls -al ~/.ssh
$ ssh-keygen -t ed25519 -C “john_doe@example.com
$ ssh-keygen -t rsa -b 4096 -C “john_doe@example.com”

Adding the SSH key to the SSH agent

In the section, we will add the SSH key to the ssh-agent.
Firstly, we need to start the ssh-agent manually(this can also be auto-launched) by typing the following command in the terminal

$ eval “$(ssh-agent -s)”
> Agent pid 59566
$ ssh-add ~/.ssh/id_ed25519
$ ssh-add ~/.ssh/id_rsa

Copying the Public SSH Key

The first step would be to get the public key which we are going to save in our GitHub account to connect to it.

$ cd ~/.ssh
$ ls
$ cat id_ed25519.pubor$ cat id_rsa.pub

Adding SSH key to Github Account

In our GitHub account, we will navigate to the SSH and GPG keys section on the settings page.

$ ssh -T git@github.com

Conclusion

To avoid going through the pains of having to input our username and personal access tokens at each visit when connecting to Github, you should use an SSH key.

Reference

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anselem Odimegwu

Anselem Odimegwu

6 Followers

A programming enthusiast. Constantly learning and unlearning.