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"
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 "firstname.lastname@example.org
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:
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:
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 email@example.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:
4. Add RSA key to SSH
Next, add an RSA key to SSH using the command:
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."
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 firstname.lastname@example.org
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:
Instead, use the SSH URL;
Additionally, you can set the URL to use SSH for git push using the command:
git remote set-url origin email@example.com:<Username>/<Project>.git