Beginning August 13, 2021, Github.com no longer accepts account passwords when authenticating Git operations.
One of the allowed ways for authenticating Git operations is through using SSH key.
This is a two step process. 1. Generate SSH key 2. Uploading public SSH key to GitHub
1. Generating SSH key
1. Open a terminal (cmd on windows)
2. On your home directory type the following command ssh-keygen -t rsa
3. This will prompt you to enter a filename to store the key.
- Just press enter to accept the default filename (/Users/you/.ssh/id_rsa)
- Then it will ask you to create a passphrase. This is optional, either create a passphrase or press enter for no passphrase
- When you press enter, two files will be created
- Your public key is stored in the file ending with .pub, i.e. ~/.ssh/id_rsa.pub
2. Uploading public SSH key to GitHub
- Copy content of your public key file id_rsa.pub to your clipboard.
- Visit https://github.com/settings/profile
- On the left-hand side menu, you will see a link "SSH and GPG keys"
- Click on that link which will take you to a page where you can enter your public SSH key that you copied earlier.
- Click the button which says ‘New SSH key’
- Then enter a title e.g. newMBP
- Paste the public SSH key in the key textbox
- Click "Add SSH key"
Switching remote URLs from HTTPS to SSH
In case your repository is set to use HTTPS protocol then you will have to switch to SSH to start using SSH key based authentication.
- Open Terminal.
- Change the current working directory to your local project.
- List your existing remotes in order to get the name of the remote you want to change.
$ git remote -v
> origin https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY.git (push)
- Change your remote's URL from HTTPS to SSH with the git remote set-url command.
$ git remote set-url origin firstname.lastname@example.org:USERNAME/REPOSITORY.git
- Verify that the remote URL has changed.
$ git remote -v
# Verify new remote URL
> origin email@example.com:USERNAME/REPOSITORY.git (fetch)
> origin firstname.lastname@example.org:USERNAME/REPOSITORY.git (push)
With this you should be all set to start using SSH key based github authentication.