DEV Community

Cover image for Git Authentication Errors
Chuck
Chuck

Posted on • Edited on

Git Authentication Errors

Cover Photo by Scott Webb on Unsplash

Context

While working on lab assignments for Flatiron School I started noticing a surprise error message when pushing my assignments to GitHub: cannot read username for GitHub. This post is describing my discoveries, a work around, and an eventual discovery as a postscript at the end.

NOTE: This is not a tutorial on how to set up GIT on your computer, but is a troubleshooting tutorial of my experiences.

My Workflow

So, when I start a new lab my workflow is pretty straight forward:

  • Browse to the Learn-co(Flatiron's learning platform) Repo
  • Fork the repository to my account.
  • Clone the repository to my computer.

Cloning

I currently use JetBrain products to develop, and there is a great browser plugin that adds clone links to my GitHub repositories, interacts with JetBrains Toolbox.

Alt Text

By click on the appropriate icon, I can open the project in Rubymine or Webstorm or any other Jetbrain application. This automatically clone the project and asks if I want to open the application. This has been my workflow.

Alt Text

Image by mohamed Hassan from Pixabay

Error!

Troubleshooting

  • So, the first time the surprise error message appeared, cannot read username for GitHub, I thought it might be my SSH setup, since I had recently upgraded my Linux OS. So, I checked:
ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

But it returned with a successful message.

  • Then I thought it may have been the Learn gem which I use to push completed lessons back to the repo, but it authenticated just fine.
  • Then the error happened again in a different repo not connected with Learn and after some investigating I realized the issue was not associated with a GitHub of Learn. The problem but that I when cloning via the Jetbrains browser plugin, it was cloning via HTTPS instead of SSH.

Fix HTTPS credentials

DISCLAIMER: This solution works for my system. I have a single user system not connected to a work network, just a home office. Please investigate the best solution for you and your own security.

Git Credentials

Per the GIT documentation: "Git will sometimes need credentials from the user in order to perform operations; for example, it may need to ask for a username and password in order to access a remote repository over HTTP."

  • After reading the documentation, I decided to set up as Git Credentials Store.
  • Create: ~/.git-credentials empty file.
  • Setup global credentials helper:
git config --global credential.helper store
Enter fullscreen mode Exit fullscreen mode

The first time you push to a https repository, you will still need to enter your username and password, but after that it will be stored in the file you created in unencrypted text.

If you examine the git-credentials file the site is saved in the following format: https://user:pass@example.com.

Postscript

After setting up Git Credentials, I found a setting in the browser plugin to clone using SSH.
Alt Text

Other Reading

Top comments (0)