github ssh key devops

When you work with Github, it will be very handy to use command line for the base operations, like git clone, git push, git pull and so on.

If you have 2FA enabled, you need to generate a token for every application that needs to login via https to your repository, due to the higher level of security added by the auth mode.

In case you don’t have 2FA enabled, it could be very useful to execute thos commands without the need to input username and password every time.

This is where SSH comes to rescue, and it uses the principle seen in my past article ( ) to allow a user to login without credentials. Let’s follow the process to make this work!

Generate a key pair (public/private) for the user

Encryption is your friend, with public/private keys combination and identity management, it is possible to easily setup a password-less connection via ssh for a given user.

All you have to do is run the ssh-keygen command that comes bundled in ssh package for each linux distribution. In the sample below I used all defaults values to make the configuration fit standard paths:

Basically, what happens is that the ssh-keygen command is:

  • Generate a private key for the user
  • Generate a public key for the user
  • Put the generated keys in ~/.ssh/ folder with the correct permissions

Once you did this, you will have your public key, named id_rsa.pub ready in your ~/.ssh folder. Its content will be used in the next steps.

Adding the key to your Github account

First of all, login to Github.com with your credentials.

After successfully loggin in your account, go on the top right of your screen and click on your profile:

github ssh linux devops docker

Next step is clicking on the “Settings” voice of the dropdown:

In the next screen you will need to click the “SSH and GPG keys” tab on the left:

ssh linux github devops

By clicking on the right side, you can add “New SSH key”

ssh linux github devops

In the “Title” field, you can add something that helps you identify the current key, while in “Key” field, you have to put the content of ~/.ssh/id_rsa.pub file.

ssh devops linux github

Once you added the key, you could be prompted to input your password, and at the end of the above steps you will have your key added to your keystore:

ssh linux github devops

You got this!

Next time you’ll work with your git commands, no password will be required. Remember to do the same steps for every machine you will use to connect to github.

If you like the how-to share it with your colleagues and friends!