In the process of using git, we may encounter problems with git push to GitHub remote repository but fail, prompting you to say that this push is not authorized.
Cause: The correct SSH public key pair is not matched. Either you did not generate the corresponding public key pair and deployed the public key to the corresponding project on GitHub, or you generated the key pair and deployed the public key on GitHub, your local directory did not configure the private key (or it was previously configured but expired)
Workaround:
(1) First, generate a public key pair:ssh-keygen-t rsa-c "youemail@example.com"-F ~/.ssh/id_rsa This command to create an SSH public key pair, " Youemail@example.com "for your own e-mail address," Id_rsa "is the public key name, can be modified. After the created public key pair is stored in the local directory C:\users\[username]\.ssh\ folder, you can view
(2) The public key is deployed on GitHub, and the Id_rsa.pub file generated in (1) is opened with a text editor and the contents are copied. In the corresponding GitHub project "setting" in the "SSH and GPG Keys" select "New SSH Key", the public key content paste up, create a new SSH key.
(3) Add the private key in the git bash command line. The command to view the list of private keys is:ssh-add-l, if the output above command appears could not open a connection to your authentication agent., then enter ssh-agent Bash, you can enter SSH bash. The command to add the private key:ssh-add ~/.ssh/id_rsa, then look at the list of private keys, if you have successfully added, you can normally use Git push to update the remote repository.