Getting Started with GitHub with SSH

Athar Majeed
2 min readJun 9, 2020
Photo by Yancy Min on Unsplash

All of us have their own way of setting up the workflow. I was going through my notes and have a couple of documents that help me to set up my workflow whenever I start working on a new project or a contract. Since I have some time so that I’ll be publishing here to share with everyone and also it would be easier for me to organise and find when needed.

  • List all of your SSH keys. Just to make sure their key does not already exist on a mac. There may be a default id_rsa ssh key already.
ls -al ~/.ssh

Let’s create a new SSH key.

  • Enter the email address, I like to keep the email same as I have with my GitHub account. You can use any email as you like. This will create a private and public key pair. By default, it will generate with a default name (.ssh/id_rsa).
  • I’d suggest a move to .ssh directory and then run the following command and then enter a file name (github_id_rsa) when prompt.
  • Also, set a password when prompt. Write it down somewhere, I usually forget.
ssh-keygen -t rsa -b 4096 -C "athar@tyrocircle.com" 

Adding an SSH key to an ssh-agent

  • We need to add our SSH key to an ssh-agent. There are many options out there (from homebrew or MacPorts). I’d strongly suggest using a default macOS.
  • Open up another terminal and enter the following command eval "$(ssh-agent -s)") to run the agent in a background.
  • On the latest macOS, all the configuration stored on a config file. We can create a new file. ~/.ssh/config
vim ~/.ssh/config
  • Enter the following content in the file. Just to remember the file name should be same.
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/github_id_rsa
  • Last the step is to add the key to the agent. Just to make sure the file name is the same as before. This will also store the passphrase in a mac keychain.
ssh-add -K ~/.ssh/github_id_rsa

Add an SSH key to GitHub account

  • From a terminal, we can run the following command to get the public key. pbcopy < ~/.ssh/github_id_rsa.pub
  • Login to GitHub account, go to ‘Settings’ page and then choose SSH and GPG keys.
  • Create a new SSH key. Give a name and then paste the public key

Clone the GitHub repo

Now, you have access to all of your GitHub repos. There is no need to enter username and password anymore.

--

--

Athar Majeed

Tech Entrepreneur | Software Engineer | Co-Founder | Cloud Enthusiastic.