Photo by Silas Köhler on Unsplash
Do you remember your coding world before you met git? I do! Severals files like version-1.cpp
, version-2.cpp
, final.cpp
, final-please-work.cpp
took a lot of place on my laptop when I just started coding. Then revelation — I can use a versioning system like git. Singing up to GitHub completely changed my coding convenience. It took me almost a year to discover the next big step: adding an SSH key (and now I can’t imagine my daily work without it!).
SSH keys are nothing more than an authorization method that allows you to avoid typing the password each time when you want to connect from your trusted computer to the server (in our case to your GitHub). The method is safer than a traditional password and based on strong asymmetric cryptography (to more details about that mechanism visit Wikipedia. Everything is based on a pair of keys — public and private. The first one is sent to the server and openly distributed to anyone on the Internet, the second should be available only for you on your local machine.
SSH keys are really popular, so Github prepared a special mechanism to make the process of adding key as simple as can be. I describe it below step by step (for Linux users):
ssh-keygen -t rsa -b 4096 -C "youremail@test.com"
What does it mean?
You will be asked by the tool where the key should be located and if you want to secure it with a passphrase. In the first case, you can just click enter — it will select a default location(/home/you/.ssh/id_rsa
). After that pair of keys will be generated.
To avoid typing passphrase from key every time when you are using SSH communication, you can use a tool called ssh-agent. Firstly, you should start ssh-agent in the background by typing in terminal:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
Remember to replace ~/.ssh/id_rsa
with your location of the private key if you have chosen a non-default location.
Dropdown with the‘Settings’ option
‘SSH and GPG keys’ tab in GitHub settings
sudo apt install xclip xclip -sel clip < ~/.ssh/id_rsa.pub
Paste copied key in the ‘Key’ area and add a meaningful title for your key (e.g. personal_laptop). At the end click the green button ‘Add SSH key’.
Confirm changes with your GitHub password if needed.
Voilà! You’ve just added your SSH key to GitHub. Now you can programming in a more comfortable and safer way!
Good luck and happy coding!