The git push code keeps reporting Permission denied, please try again. How to solve it?

Today I tested a git on my native windows7 and wanted to push the git code to the code server. As a result, git always reports errors

$ git push -u origin master
[email protected]'s password:
Permission denied, please try again.
[email protected]'s password:
Connection closed by 192.168.0.208 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

After trying several times, the same error was reported. I tried to change the password of the user on the git server, tried to change the account on git, the error still exists, and git keeps reporting permission denied, please try again.

There is really no way, I want to try using ssh-key to log in without password to see if it can be solved.

1. First, right-click [git bash here] in the blank of the project root directory

2. Enter in the bash command line to generate the public and private keys of ssh, which will be placed in the C:\Users\Administrator\.ssh directory by default

#进到ssh根目录
cd ~/.ssh/
#设定git账号和邮箱
git config --global user.name "zhangsan"
git config --global user.email "[email protected]"
#生成ssh密钥,可选是否加邮箱,如果不加就去掉-C参数和邮箱(正常情况下一路回车)
ssh-keygen -t rsa -C "[email protected]"
#假如以前可能生成过密钥,所以她可能会提醒你是否要覆盖(y/n)?输入y并回车即可。

3. Check the public key, and copy all the checked keys (along with the mailbox) for later use.

cat id_rsa.pub

4. Log in to the git server zhangsan account (the user who typed in bash just now is also zhangsan), and then add the public key just found in the user's "Settings---SSH KEY".

5. Don't forget to return to our project directory in bash

#我的项目放在d盘的目录里,先进d盘
cd /d/
#再进项目根目录
cd CsharpTemp/20200518hellowordNetCore/HelloworldForLinuxDocker/

6. Submit the code again

git add .
git commit -m "x the first commit netcore code for linux docker"
git push -u origin master

You can see that we did push the code to the git server without secret this time successfully.

I don't know why, but I guess it may be because I have done password-free login for other git accounts. Regardless, the problem is solved anyway, so be it.

----------Chuan Jianguo: No one knows git better than me----------------------

Guess you like

Origin blog.csdn.net/xoofly/article/details/106392249