2012-03-05 115 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