2012-03-05 119 views
17

我似乎已经从另一个(本地)存储库推送到github帐户后失去了我的权限。我现在收到以下错误:权限错误github(ssh密钥无法识别)

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. 

有什么想法?

回答

50

我解决了这个问题,下面这个步骤 - 分步说明:

步骤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 

然后,转到hithub,并做到:

  1. 转到您的帐户设置
  2. 点击“SSH密钥”,在左边栏中
  3. 点击“添加SSH密钥”
  4. 密钥粘贴到“重点” 领域
  5. 点击输入你的GitHub密码 “添加键”
  6. 确认操作

步骤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

+0

ssh-add does事情。再次感谢... – 2014-10-16 16:08:56

+0

对不起,您如何输入路径?我的路径是C:\ Documents and Settings \ admin \ .ssh文件夹。输入路径的格式是什么? – Thinkerer 2014-12-14 17:21:00

+0

而不是'sudo apt-get install xclip'您可能需要运行'brew install homebrew/emacs/xclip-mode' – 2016-02-19 22:37:16

1

你必须用命令

ssh-copy-id [email protected] 

ssh-agent你的ssh-ADD之前应该运行在服务器上导出你的密钥。 你可以把此行/etc/rc.local如果你是Linux下:

eval $(ssh-agent) 

编辑:现在我知道你使用Windows,所以看到这个线程:Getting ssh-agent to work with git run from windows command shell

+0

谢谢你的提示 - 我使用的混帐的bash Windows上的接口和ssh-copy-id不被识别为命令。 – mike 2012-03-05 02:39:57

+0

所以,你必须从'id_rsa.pub'手动复制生成的行,并将其附加到服务器上的文件'〜user/.ssh/authorized_keys' – 2012-03-05 02:44:31

+0

请参阅我的编辑...;) – 2012-03-05 02:49:12

3

如果你已经在〜/ .ssh公钥(并已补充说,关键是你的github账户),你可能只需要加载你再次键入SSH代理。

要测试SSH剂具有键,输入ssh-add -l 如果结果是:

The agent has no identities. 

然后只需将钥匙装入SSH代理这样的:

ssh-add ~/.ssh/github_rsa 

(github_rsa是我的机器上存储的SSH密钥的名称,这个文件可以被命名为:id_rsa)

之后,您必须输入y我们的密钥密码(这可能是您登录github的密码)。如果你得到这样的消息:

Identity added: /Users/name/.ssh/github_rsa (/Users/cpotzinger/.ssh/github_rsa) 
2

做一个$ 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. 
+0

简单而容易。 – workdreamer 2015-02-23 11:07:54