DEV Community

Cover image for Http Request Exception Encountered [SOLVED]
Franklin Ohaegbulam
Franklin Ohaegbulam

Posted on • Originally published at frankiefab.hashnode.dev

Http Request Exception Encountered [SOLVED]

GitHub recently stopped the use of usernames and passwords to authenticate git push due to identity and security reasons. And this new development was challenging for me because I found it difficult at first to push my project to the remote repository.

The old way to associate a commit was:

git config --global user.name "your username"
git config --global user.email "your email"
Enter fullscreen mode Exit fullscreen mode

The above method works when you fork and clone a repository using HTTP. Following this update, if you try pushing to GitHub, you are likely to come across this error;

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

Solution: Use an open SSH public key to authenticate the Git push

1. Generate an SSH public key

Open your GitBash desktop app, and enter the command:

ssh-keygen -o -t rsa -C "yourname@email.com
Enter fullscreen mode Exit fullscreen mode

You should see, "Enter file in which to save the key". Hit the ENTER key to bypass, and use the default file location ~/.ssh/id_rsa. You will also be prompted to enter a passphrase, which is the password for the key. Press the ENTER key to skip.

Bypass the prompt "Enter file in which to save the key" by hitting the ENTER key. Do the same when asked to enter a passphrase.

If you already have an SSH key, skip this step and enter the following command to display your SSH key:

ls .ssh
Enter fullscreen mode Exit fullscreen mode

This command displays your SSH key, if you have one.

If none exist yet, you should get notified with the message "No such file or directory."

2. Show the contents of your SSH public key

In GitBash, run the command:

cat .ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

This returns a long string of SHA256 encrypted messages known as "key fingerprints." You should get something like this:

The key fingerprint is:
SHA256:BG/dbxxxxxxxxxxxxxxx/pE4xxxxxxxx yourname@email.com

The key's randomart image is:
+---[RSA 1234]----+
|      oo o       |
|       oo.+.o o  |
|        +++Bo*.o |
|       o .====B. |
|       ES.+o*+o..|
|        . ooo=++=|
|         ...o.o=o|
|           o .   |
|            .    |
+----[SHA256]-----+
Enter fullscreen mode Exit fullscreen mode

Copy this key fingerprint to the clipboard.

3. Add SSH to the SSH agent program

To add SSH to the SSH agent, enter this instruction in your GitBash:

ssh-agent -s
Enter fullscreen mode Exit fullscreen mode

4. Add RSA key to SSH

Next, add an RSA key to SSH using the command:

ssh-ad .ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

The RSA key is alphanumeric and looks like gc_54340.

5. Sync the SSH key to your GitHub account

Now, sign in to your account on GitHub. Navigate to Profile, then Settings, and locate the tab labeled "SSK and GPG keys."

GitHub profile settings

SSH and GPG keys

SSH key section

Click on "New SSH key," then paste the encrypted SSH key. Give this key a name you can easily remember; it could be a pet name or your PC name.

6. Optional: Verify the authentication between your local system and GitHub

ssh -t git@github.com
Enter fullscreen mode Exit fullscreen mode

Voila! You just set up a public SSH key. Now, you can clone a repository via an SSH URL and successfully push your commits to your remote GitHub repository, like:

You don't have to copy the HTTP URL of a repository, which looks like this:

https://github.com/<Username>/<Project>.git
Enter fullscreen mode Exit fullscreen mode

Instead, use the SSH URL;

git@github.com:<Username>/<Project>.git
Enter fullscreen mode Exit fullscreen mode

Additionally, you can set the URL to use SSH for git push using the command:

git remote set-url origin git@github.com:<Username>/<Project>.git
Enter fullscreen mode Exit fullscreen mode

References

Top comments (0)