Have you ever encountered this error before? (Perhaps when cloning a private github repository):
Well, I have, and I finally figured it out
Enough of foreplay, let's get serious.
It seems that github enhanced their security such that inputting your password and username is not enough for them, since an attacker can easily get them through social engineering. There are two ways of authentication (those that I know of)
They include:
Using Secure SHell (SSH) with its key
Using the Command Line Interface
When cloning the preferred github repository, you will have to use the SSH url
Before that, you have to create a ssh key, which is a private and public key which
authenticate you. These keys are tedious and time-consuming to crack.
NOTE: If the repository already exists, check it's remote repository url using the below command. The URL is probably HTTPs; change it to the SSH url.
git remote -v
#https url: https://github.com/Jaarabytes/dotfiles.git
#ssh url: git@github.com:Jaarabytes/dotfiles.git
You can change it to the ssh version through:
git remote set-url origin <ssh-url>
If the repository doesn't exist, you can proceed:
They can be generated by the following command:
ssh-keygen -t rsa -b 4096 -C < your_email@example.com >
I will explain the commands:
ssh-keygen
- Generates the SSH key pair-t rsa
- Uses RSA algorithmb 4096
- Uses 4096 bytes for generationC <youremail@example.com>
- your email is used as commentThis will be the response from the terminal:
Generating public/private ALGORITHM key pair.
You will be prompted to input and confirm a safe passphrase. ( You may also press Enter to skip this process. )
Add your ssh key to the ssh agent by running the below command (Depending on the system you are running, you may need superuser privileges)
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
You may want to verify if your SSH key was added. Use the below command:
ssh -T git@github.com
Onto the finals where we add the ssh key to our github account:
Directions to take:
SSH and GPG keys
;Copy the contents of the contents of the id_rsa.pub file which is under the hidden .ssh directory and paste it as your personal access token
This is what you should be pasting in the field:
From there on, I believe there will be minimal issues encountered however what if you cloned the repository using the http client but now cannot authenticate? Don't fret.
Head towards the repository directory using the cd command and type in the following command in your terminal:
git remote set-url origin < ssh_github_repo_link >
The above command resets your remote-origin url to the SSH url. This means that when performing remote changes to the repository, it will use the SSH url.
You can also view the remote origin url through the below command:
git remote -v
More info here :
First, gh
has to be installed.
sudo apt install gh
Remember to input your password since the command uses sudo
and this requires superuser privileges. I am already running as root
so I do not need to use sudo
For those who do not know, the github CLI is just you, logged in to your github account and navigating it using your terminal.
Type in the command:
gh auth login
You will be asked questions, for which you will answer according to your preference. After answering, you will be
given a one time code. Which you will copy then press Enter
to open your browser and input the one-time code.
NOTE: Make sure that you are using a safe network (to prevent you from being hacked). Just use your own mobile phone hotspot.
After that you would have successfully logged in and freely access your projects
If you are a real reader:
I prefer the SSH method since it carries less risk though, but that's just me. Stay safe and git to work.
Thanks for reading!