Posts

Git rid of it

Have you ever encountered this error before? (Perhaps when cloning a private github repository):



Git authentication failed? fatal: No credential store has been selected. Support for password authentication was removed in 13th August 2021.

git error that prompts for authentication
Well, I have, and I finally figured it out



Nerd emoji


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:


1. The SSH method (my favorite)


When cloning the preferred github repository, you will have to use the SSH url ssh url clone github repository
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:




This 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: github personal account settings Directions to take:




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:


ssh key


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 :


https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent



2. The Github CLI method


First, gh has to be installed.


sudo apt install gh


gh in action


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


logging in using gh


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


successful login using gh


If you are a real reader:


https://cli.github.com/manual/gh_auth_login

I prefer the SSH method since it carries less risk though, but that's just me. Stay safe and git to work.


Dum tss gif from gif tenor Thanks for reading!