从另一个(本地)存储库推送到github帐户后,我似乎失去了对github帐户的权限。我现在收到以下错误:
git push
Permission denied (publickey).fatal:
The remote end hung up unexpectedly
然后,我按照以下步骤重新生成密钥:
ssh-keygen
Set up an ssh on my account for this laptop, using id_rsa.pub
但是,这是不成功的。当我尝试以下代码建议时,我收到以下错误:
ssh-add -l
Could not open a connection to your authentication agent.
有什么想法吗?
我按照这个分步说明解决了这个问题:
第1步:检查SSH密钥
$ cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory
# If it says "No such file or directory" skip to step 3. Otherwise continue to step 2.
第2步:备份并删除现有的SSH密钥
$ ls
# Lists all the subdirectories in the current directory
# config id_rsa id_rsa.pub known_hosts
$ mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory
$ cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup
$ rm id_rsa*
# Deletes the id_rsa keypair
第3步:生成新的SSH密钥
$ ssh-keygen -t rsa -C "[email protected]"
# Creates a new ssh key using the provided email
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
# Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
第4步:将SSH密钥添加到GitHub
$ sudo apt-get install xclip
# Downloads and installs xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
然后,转到github,并执行:
第5步:测试一切
$ ssh -T [email protected]
# Attempts to ssh to github
好的,你会看到
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
否则(它发生在我身上),你会看到
Agent admitted failure to sign using the key.
# debug1: No more authentication methods to try.
# Permission denied (publickey).
要解决这个问题
$ ssh-add
# Enter passphrase for /home/you/.ssh/id_rsa: [tippy tap]
# Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)
原始信息
https://help.github.com/articles/generating-ssh-keys
https://help.github.com/articles/error-agent-admitted-failure-to-sign
如果您已经在〜/ .ssh中有一个公钥(并且已经将该密钥添加到您的github帐户),您可能只需要再次将密钥加载到SSH代理中。
要测试SSH代理是否具有密钥,请键入ssh-add -l
如果结果为:
The agent has no identities.
然后只需将密钥加载到SSH代理中,如下所示:
ssh-add ~/.ssh/github_rsa
(github_rsa是我的机器上存储的SSH密钥的名称。此文件也可以命名为:id_rsa)
之后,您必须输入密钥的密码(这可能是您登录github的密码)。如果你收到这样的消息:
Identity added: /Users/name/.ssh/github_rsa (/Users/cpotzinger/.ssh/github_rsa)
做一个$ ssh-add
这对我来说也可以解决以下问题以及gitlab
jovimac-2:work joviano$ git clone [email protected]:bjetfweb.git
Cloning into 'bjetfweb'...
Access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
您必须使用该命令在服务器上导出密钥
ssh-copy-id user@host
和ssh-agent
应该在你的ssh-add之前运行。如果您在Linux下,可以将此行放在/etc/rc.local
中:
eval $(ssh-agent)
编辑:现在我知道你使用windows,所以看看这个帖子:Getting ssh-agent to work with git run from windows command shell