Skip to content

Instantly share code, notes, and snippets.

@glegoux
Last active September 11, 2017 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glegoux/6f29ec086bd8eb870585c2c28d6cebc9 to your computer and use it in GitHub Desktop.
Save glegoux/6f29ec086bd8eb870585c2c28d6cebc9 to your computer and use it in GitHub Desktop.
SSH key authentication for GitHub repository

1) Generate your pair of SSH keys:

ssh-keygen -t rsa -b 4096 -C "<email>@example.com"

Add a passphrase is better. Here your pair of keys:

  • private key: without extension (keep that secret only for you)
  • public key : with extension .pub (for everybody)

See https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ .

Give a common suffix name to your keys for example github_id_rsa in your ~/.ssh/ folder.

2) Copy your SSH public key via keyboard to web interface:

sudo apt-get install xclip
cat ~/.ssh/github_id_rsa.pub | xclip -selection clipboard

at https://github.com/settings/keys. Give a name to your SSH public key.

3) Manage your ~/.ssh/config if multiple pairs of SSH keys:

...
Host github.com
User <username>
IdentityFile ~/.ssh/github_id_rsa
...

4) Modify your config git:

Go to your git respository and do:

git remote set-url origin git@github.com:<username>/<repository.git>

5) Test your SSH connection and see your configuration:

$ ssh -T git@github.com
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access
git config --list

6) Push:

You can now do git status, add, commit and push without typing password and using SSH keys authentication (and type your passphrase kept by SSH agent if you have that).

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment