这是github的安全设置,当你直接用https的方式向github push时,会要求输入用户名和密码。
解决方式是:git clone时改用SSH的方式。
1、在本地创建ssh密钥。
参考:https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
打开Git Bash,输入:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
> Generating public/private rsa key pair.
> Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
2、将创建的密钥复制添加到github的settings的ssh设置里。
参考:https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account
注:1、本地的ssh公钥一般在C:/user/用户名/.ssh/xxxxrsa.pub里,另外一个同名但是没有后缀名的文件里保存的是私钥;
2、也可以通过git gui的help->ssh查看SSH Key:
3、git clone 选择SSH地址,而不是HTTPS地址:
git clone git@github.com:your_repository_address.git
4、有时候git clone时会出现如下问题:
原文网址:https://help.github.com/en/articles/error-agent-admitted-failure-to-sign
Error: Agent admitted failure to sign
In rare circumstances, connecting to GitHub via SSH on Linux produces the error "Agent admitted failure to sign using the key"
. Follow these steps to resolve the problem.
When trying to SSH into GitHub on a Linux computer, you may see the following message in your terminal:
$ ssh -vT git@github.com
> ...
> Agent admitted failure to sign using the key.
> debug1: No more authentication methods to try.
> Permission denied (publickey).
For more details, see this issue report.
解决方式是:
# start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
> Agent pid 59566
$ ssh-add
> Enter passphrase for /home/you/.ssh/id_rsa: [tippy tap]
> Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)