Http Request Exception Encountered [SOLVED]
Tags: git, github, bug, webdev
Published: 2023-02-12 12:56:11

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:

```css
git config --global user.name "your username"
git config --global user.email "your email"
```

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:

```bash
ssh-keygen -o -t rsa -C "yourname@email.com
```

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:

```bash
ls .ssh
```

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:

```bash
cat .ssh/id_rsa.pub
```

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

```bash
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]-----+
```

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:

```bash
ssh-agent -s
```

### 4\. Add RSA key to SSH

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

```bash
ssh-ad .ssh/id_rsa
```

> 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7b2yp5boekq2pa2y6etj.png )

![SSH and GPG keys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf2bmdrdqtl619iw6bmr.png)

![SSH key section](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmfssev2iqo1bvjdwx5s.png)

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

```bash
ssh -t git@github.com
```

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:

```bash
https://github.com/<Username>/<Project>.git
```

Instead, use the SSH URL;

```bash
git@github.com:<Username>/<Project>.git
```

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

```bash
git remote set-url origin git@github.com:<Username>/<Project>.git
```

### References

* Stackoverflow: [Push to GitHub without a password using ssh-key](https://stackoverflow.com/questions/14762034/push-to-github-without-a-password-using-ssh-key)
    
* [How to Clone Using SSH in Git?](https://gitprotect.io/blog/how-to-clone-using-ssh-in-git/)
    
* [Set up SSH public key authentication to connect to a remote system](https://kb.iu.edu/d/aews)