Published: 2024-02-24
Last Modified: 2024-11-11 15:46 UTC
A couple of years ago, GitHub changed some of their security policies and now you are not able to push (and sometimes pull) code to repositories with the normal username and password login method. You now need to use SSH keys.
The method outlined here can work with Linux, Windows, Mac OS and probably other OSes too, but some of the commands and steps might differ a bit depending on your system. The good part is that what you learn here will also apply when you need to access other services that use a similar authentication method!
There are a couple of things that you will need:
Once you have that, you need to verify that you don’t already have existing SSH keys. You can do so by executing $ ls -al ~/.ssh | grep pub
in your home directory. Another option is to check the .ssh
directory with a file browser.
If your output looks something like that, and you already have a .pub file, you already have some keys, and most likely you will be able to use them with GitHub. Compatible filenames would be something like id_rsa.pub
, id_ecdsa.pub
, or id_ed25519.pub
. Bear in mind that these are default file names and yours might be different.
If you don’t have keys, we will generate them in the next section. If you do, you can skip it.
Generating your keys will be as easy as running this command:
When you run it, it will ask for a name for the key, you can leave it blank for the default name if you want. Then it will ask for a password, you can leave this blank as well if you really want to.
It will output a bit more information, and generate two files in your .ssh
directory: id_rsa.pub
, which is your public key, and id_rsa
, your private key.
It is very important that you never share your private keys! Only ever share and use your public key for anything that might need it.
Now you can go to your GitHub settings page and click the button that says “New SSH Key”
Now you will be given two prompts. Give a descriptive title to this key, for example, “Manjaro desktop”. In the next field, you need to paste the entire content of your .pub
file (All of it).
Now just click “Add SSH Key”
From the SSH keys page, you will also be able to see information regarding all your added keys and remove them if you need to.
Now, to test if your keys are working, do the following command: ssh -T git@github.com
, it will take a few seconds and then output something similar to this:
If so, congratulations! Your SSH keys are added and you can start using them with GitHub.