How to set up GitHub to use SSH credentials on Linux or macOS

Joshua Michael Calafell
2 min readMay 23, 2020

--

Setup git to use SSH instead of login credentials to speed up productivity and interface with GitHub in a more secure way.

  1. Open up your terminal and make a new key. Follow the prompts to enter the correct info you want to be associated with your new key.
$ ssh-keygen

Pro Tip: You could also make one without going through all that where -t is the type (we are choosing rsa) -b is the size in bytes (you can choose 4096 which is the strongest, 2048 which will work, or 1024 which is not recommended as it is weak), and -c is your email address.

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

2. Now that you have your key, let’s import it into ssh-agent where <path-to-my-ssh-folder> is the directory in which your SSH keys are store, usually ~/.ssh.

$ ssh-add <path-to-my-ssh-folder>/id_rsa

3. Now that we have made a key, and imported it, we can set up git to use it instead of login credentials. Note: You must have git installed on your machine.

$ git config --global --edit will pull up your .gitconfig document that was generated when gitwas installed.

Uncomment the lines for your nameand email.

4. Finally, get an output of your public SSH key and copy it into GitHub.

cat <path-to-my-ssh-folder>/id_rsa.pub will print out your key. Copy this and keep it in your clipboard.

5. Log in to GitHub, or create an account if you’re not already a member.

6. Go to the Settings tab in the upper right corner > Go to SSH and GPG Keys > Click green New SSH key button

7. Copy your SSH key into the input field and give it a title and then, finally, click Add SSH key to save.

Congrats! You are now set up to use git on your machine using SSH credentials and not a username and password. This is more secure and will speed up your workflow and productivity. Clap if you liked this article!

--

--