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:


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 (public key).

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

ssh-add ~/.ssh/id_rsa


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

If you're still being asked for a password

Most likely, your remote is set to instead of ssh:// Luckily, there is a simple 1 liner fix:

git remote set-url origin ssh://

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/ | ssh 'cat >> ~/.ssh/authorized_keys'
Dominik Tarnowski
I write code.