Setting Up Your SSH Configuration File To Work With GitHub

January 10, 2017

Setting Up Your SSH Configuration File To Work With GitHub

When I first started coding, I didn’t know anything about ssh configuration files. So when I would commit my code to GitHub, I first started out by cloning repositories using an HTTPS based remote.

Git logo

This meant I had to enter my GitHub username and password every time I wanted to push and pull. Needless to say, the more code I wrote, the more tedious this became.

So I began looking for a faster way and found the ssh configuration file.

What is an SSH Configuration file?

The SSH configuration file lets your system automatically read options from the config file automatically.

So instead of having to type out something like the below,

ssh bruce@example.com -p 2200

you can type something like ssh bruce.

It’s much faster than HTTPS.

Step 1: Set up SSH Configuration

If you’re on a Mac OSX or Linux system, you can simply type:

touch ~/.ssh/config

This creates an empty config file if it doesn’t already exist.

Step 2: Enter the options in your SSH configuration file

Host github.com
  User treble37
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/example_github_key

Step 3: Generate Public and Private keys

cd ~/.ssh

ssh-keygen -f example_github_key -C "example_github_key"

During this step, you will be asked to provide a password. Please pick a strong password when you generate this key.

Step 4: Set up GitHub With Your Private and Public Keys

cat ~/.ssh/example_github_key.pub

Copy and paste the results of the cat command above into your GitHub account. You can find some good instructions from GitHub here.

The below screenshot shows where you add your public key output by the cat command.

GitHub ssh configuration key settings page

Now, when you do a push/pull with GitHub, you’ll only have to enter the password credential you made in Step 3.

Summary

Creating an SSH configuration file to work with GitHub is easy.

  • Setup the SSH configuration file
  • Enter the options in the SSH configuration file
  • Generate public and private keys
  • Enter your public key in GitHub

Profile picture

Written by Bruce Park who lives and works in the USA building useful things. He is sometimes around on Twitter.