Git Authentication Errors
Tags: git, security, webdev
Published: 2019-11-05 12:48:47

---
title: Git Authentication Errors
published: true
description: 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.  
tags: git, security, webdev
series: Git Authentication
cover_image: https://thepracticaldev.s3.amazonaws.com/i/div5irmfz2fa4jdwukjw.jpg
---
<small>Cover Photo by [Scott Webb](https://unsplash.com/@scottwebb?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/security?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)</small>

## Context
While working on lab assignments for [Flatiron School](https://flatironschool.com/) 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](https://thepracticaldev.s3.amazonaws.com/i/afgsuvmnml8156o20u3u.png)

By click on the appropriate icon, I can open the project in [Rubymine](https://www.jetbrains.com/ruby/) or [Webstorm](https://www.jetbrains.com/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](https://thepracticaldev.s3.amazonaws.com/i/uo319khq248uiort3w1u.jpg)
<figcaption>Image by <a href="https://pixabay.com/users/mohamed_hassan-5229782/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3085712">mohamed Hassan</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3085712">Pixabay</a></figcaption>

## 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](https://help.github.com/en/github/authenticating-to-github/testing-your-ssh-connection):
```
ssh -T git@github.com
```
But it returned with a successful message. 
- Then I thought it may have been the [Learn](https://rubygems.org/gems/learn-co/versions/1.0.4) 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
```
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](https://thepracticaldev.s3.amazonaws.com/i/c01452jtyc7ti431w3rz.png)



### Other Reading
- [Using GNOME Keyring as Git Credential Helper](https://blog.scottlowe.org/2016/11/21/gnome-keyring-git-credential-helper/)
- Stored credentials in 'git credential-osxkeychain'[Stackoverflow](https://stackoverflow.com/questions/11067818/how-do-you-reset-the-stored-credentials-in-git-credential-osxkeychain)