在从另一个(本地)存储库推送到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.
有什么想法吗?
答案 0 :(得分:53)
我按照这个分步说明解决了这个问题:
第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 "your_email@youremail.com"
# 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 your_email@youremail.com
第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
然后,转到hithub,然后执行:
第5步:测试所有内容
$ ssh -T git@github.com
# 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
答案 1 :(得分:3)
如果您已经在〜/ .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)
答案 2 :(得分:3)
做$ ssh-add
这对我来说也有助于解决以下问题以及gitlab
jovimac-2:work joviano$ git clone git@git.xyz.com: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.
答案 3 :(得分:1)
您必须使用命令
在服务器上导出密钥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