In this tutorial, we will configure GitHub ssh keys.
- Generate an ssh key pair on your ubuntu system.
- Adding this key to Github
This will solve various problems like sometimes 2-factor authentication won't work or you want to allow only a few devices to access the repository.
Step 1: Generating ssh keys
- Open your terminal and run the command below.
ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org"
- It will ask you a few questions, keep on pressing enter till you get the output something like below.
- Now run the below command to print the key on the screen.
- Now copy the output generated.
Step 2: Adding the copied key to Github
- Opening github.com -> settings -> SSH and GPG keys or you can visit this URL: https://github.com/settings/keys
- On the top right, click on New SSH key button.
- Put any title like your laptop name or anything just to differentiate if you added multiple keys later.
- In the key field paste the copied key and click on Add SSH key.
Step 3: Changing git origin from https:// to ssh
- Open your terminal or cd to the cloned repository and run
git remote set-url origin email@example.com:<github username>/<repository name>
- Don't forget to change gitusername, repositoryname to yours, like this
- git remote set-url origin firstname.lastname@example.org/nitinraturi/django-structure
Now ssh keys are set up, you can try pushing to your Github repository.