Dom.

SSH Keys

Generating a new key

Before you generate a key, make sure you don't already have one:

ls -la ~/.ssh | grep .pub

If you don't see any files, you'll need to generate a pair of public/private keys. There are many different types you could use, but I would recommend just sticking with the default:

ssh-keygen

The command will prompt you to enter a location to output the public key (stick to the default) and a password. After that, there will be 2 files generated in your ~/.ssh folder; id_rsa (private key) and id_rsa.pub (public key).

The last step is adding the private key to the ssh-agent:

ssh-add ~/.ssh/id_rsa

Github

You can even add your public SSH key to GitHub, all you need to do is copy and paste the contents of id_rsa.pub to the list of Authorized SSH keys.

If you're still being asked for a password

Most likely, your remote is set to https://github.com/user/repo.git instead of ssh://git@github.com/user/repo.git. Luckily, there is a simple 1 liner fix:

git remote set-url origin ssh://git@github.com/user/repo.git

Adding key to server

For this part, you will only need the public key, and please make sure not to ever send your private key by accident. To add an SSH key to a list of trusted keys, you need to append the public key to ~/.ssh/authorized_keys:

cat ~/.ssh/id_rsa.pub | ssh user@server.com 'cat >> ~/.ssh/authorized_keys'
Dominik Tarnowski
I write code.