Jens Willmer

Tutorials, projects, dissertations and more..

GitHub SSH based authentication

This is just a quick writeup about how to setup SSH based authentication on GitHub since the GitHub documentation is missing some key parts and I search for it every time on the Internet.

Make sure openssh-client and git is installed:

sudo apt update && sudo apt install -y openssh-client git

Create GitHub SSH directory:

mkdir -p ~/.ssh/github
chmod 700 ~/.ssh ~/.ssh/github

Generate the SSH key and add your GitHub project or account as a comment to know were you use this key:

ssh-keygen -t rsa -b 4096 -C 'Comment' -f ~/.ssh/github/id_rsa -q -N ''

Create a SSH config:

touch ~/.ssh/config
chmod 600 ~/.ssh/config

Edit the SSH config and reference the GitHub key: nano ~/.ssh/config

    IdentityFile ~/.ssh/github/id_rsa

Output public key and copy it to the GitHub deploy section in project or account settings:

cat ~/.ssh/github/
Account settings
Project settings

Test the authentication to GitHub:

ssh -T [email protected]

Use the SSH URL option in GitHub to clone your repository. In case you have a existing repository that was cloned using HTTPS you can open .git/config in the root directory of your project and replace the URL with the one you get from the SSH option.