2013-01-15 197 views
50

我在關注ruby.railstutorial。我運行命令「git push heroku master」並且吐出這個錯誤。git push heroku主人權限被拒絕

Permission denied (publickey). 
fatal: Could not read from remote repository. 
Please make sure you have the correct access rights 
and the repository exists. 

我爲我的Rails應用程序 「/用戶/ lexi87/rails_projects/first_app」 裏。任何解決方案

+6

你可能想看看Heroku的指導來管理你的SSH密鑰:https://devcenter.heroku.com/articles/keys – derekerdmann

回答

65

避免此類錯誤的最佳方法是使用一對公鑰/私鑰對,而不是用於heroku的額外密鑰。這樣你(或你的系統)就不能選擇一個錯誤的密鑰來登錄heroku。

如果您遇到此錯誤,您做了錯誤的事情。檢查這個網站:https://devcenter.heroku.com/articles/keys

如果你有這個錯誤,最好的辦法是刪除不必要的密鑰,只使用一個。

如果您的系統需要多個密鑰對,您可以爲heroku設置一個密鑰。這是通過以下命令完成的:

heroku keys:add 
+21

謝謝。我不得不運行命令heroku keys:add,然後選擇id_rsa選項。 –

+0

對於Windows用戶來說,尋找低於@ mjulmer的回答方式.... – bcm

8

我面臨同樣的問題。在我的.ssh文件夾中,我有一個名爲「已知主機」的文件。我一直試圖刪除並創建新的ssh密鑰,它不起作用。最後我剛剛刪除一切的.ssh包括「已知主機」,然後創建使用新的RSA密鑰:使用我加入這個新的關鍵的Heroku

ssh-keygen -t rsa 

則:

heroku keys:add 

然後創建新的Heroku的回購,把我的應用吧:

heroku create 
git push heroku master 
0

我創建了一個鍵與

ssh-keygen -t rsa 

並使用了不同於id_rsa的文件名(在我的情況下爲heroku)。我加入了關鍵的Heroku與

heroku keys:add 

在試圖把我的主分支的Heroku我總是收到以下錯誤:

$ git push heroku master
The authenticity of host 'heroku.com
(50.19.85.132)' can't be established. RSA key fingerprint is
8b:48:5e:67:0e:c9:16:47:32:99:87:0c:1f:c8:60:bb. Are you sure you want
to continue connecting (yes/no)? yes Warning: Permanently added
'heroku.com,50.19.85.132' (RSA) to the list of known hosts. Permission
denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

當我發現的git只用我id_rsa鑰匙從另一個SSH-訪問(你可以通過你的git gui來檢查:幫助 - > SSH密鑰)。

我改名爲我的.ssh目錄C:\用戶\%USERNAME%的.ssh.ssh.bak和複製我的Heroku的私鑰和公鑰(從.ssh.bak目錄)到新創建的.ssh目錄並將其命名爲id_rsa(和id_rsa.pub)。

現在正在推動和預期一樣:

git push heroku master 
13

一些幫助Windows 7用戶使用Github的Windows客戶端安裝:

即使Heroku的工具區報告它發現我git_hub公鑰並上載,「混帳推heroku主'失敗。採取以下步驟後,它工作正常。

  1. 您的用戶文件夾下創建的.ssh文件夾,如果一個不存在。如果它是 ,那麼刪除它中的所有文件(這裏假設你可以用ssh鍵從頭開始)。

  2. 在Windows資源管理器中,右鍵單擊 的.ssh文件夾,然後從上下文菜單中的Git的bash。這與Github Windows客戶端軟件一起安裝。

  3. 在bash的窗口項目的輸入 「當提示輸入 密碼(不失去這個)。

  4. 關閉的bash shell窗口。

  5. 從命令提示符根,進入heroku keys:add。 這將找到並上傳你只是從你的/.ssh文件創建 的Heroku。

關鍵

現在你可以輸入git push heroku master來推送你的應用程序到Heroku。 注意:完成後,您需要將新生成的ssh公鑰添加到您的Github帳戶中。

+0

完美@mjulmer。試了很多選擇,但最後你的解決方案爲我工作。非常感謝。這是Windows 7用戶,當然:) –

+0

此外我認爲你的方法是什麼,我想,主要的區別是「-C EMAILADDRESS」屬性。我的情況是把Windows用戶名作爲windows @ windows-PC而不是我的電子郵件地址註冊到你的heroku。再次不確定是否真的是這個原因:) –

+0

謝謝!我兜兜與其他的答案對非Windows – bcm

4
ssh-keygen -t rsa 

上面是可選的,因爲您也可以鏈接到現有的密鑰。 Heroku會在下一步中提示選擇密鑰。

heroku keys:add 

添加您新創建的密鑰或現有的密鑰。如果你還在運行到這個問題,你很可能需要通過執行以下向鍵添加到SSH密鑰的機器的列表:

ssh-add ~/.ssh/name_of_your_rsa 

,並確認您的SSH已添加

ssh-add -l 

這應該讓你訪問推到Heroku的遠程回購。

2

在OSX上,我有遇到同樣的問題,我是越來越

no such identity: /Users/me/.ssh/yourPrivateKey: No such file or directory 
Permission denied (publickey). 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

我試圖創建使用ssh-凱基-t RSA然後用Heroku的鍵添加一個新的關鍵:添加,但它沒有幫助。

然後我發現一個名爲配置在〜/ .ssh /,和裏面的文件有:

ServerAliveInterval 300 
ServerAliveCountMax 3 

host heroku.com 
    user git 
    hostname heroku.com 
    identityfile ~/.ssh/yourPrivateKey 

所以我通過改變yourPrivateKey我的私人密鑰文件名(id_rsa默認)aaand它的工作:)

0

如果您正在使用Windows,請務必使用git-bash而不是Powershell /命令提示符。

如果你只是想重置SSH密鑰:

  1. 刪除用戶的.ssh目錄
  2. 開放混帳的bash
  3. SSH-凱基-t RSA
  4. Heroku的鍵:添加

,然後你就可以混帳推。