2013-07-14 101 views
32

我想把我的項目推到我的bitbucket上,一直在搞這個大約4天,通過無數問題解決/頁面/故障排除/教程。我不知所措,非常沮喪。我這樣做之前,但在不同的計算機...反正這裏是代碼/應答我得到無法推送到bitbucket,權限被拒絕(publickey)

~/dev/sample_app git push -u origin --all 
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established. 
RSA key fingerprint is 81:7b:2c:f5:6f:18:2b:7c:4b:ec:aa:46:46:74:7c:40. 
Are you sure you want to continue connecting (yes/no)? 
Host key verification failed. 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 
~/dev/sample_app 

我上運行10.8.4的Mac。

那麼一點已經取得了進展,最初沒有的.ssh文件夾,所以我創建了早在開始的時候,沒有known_hosts文件,所以我跑了

ssh -T [email protected] 

我選擇的是和這創造一個known_hosts文件,當我試圖再次推我:

~/dev/sample_app git push -u origin --all 
Permission denied (publickey). 
fatal: Could not read from remote repository. 

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

我的.ssh文件夾是700和鍵裏面都是600

+16

作爲一個正式的答案,回答你自己的問題實際上是鼓勵,只是讓你知道:) – iono

+0

而你的私鑰對應的公鑰是在你的bitbucket賬號上註冊的嗎? – janos

回答

5

一個更可持續的解決方案是編輯.bashrc(例如vi ~/.bashrc),然後將下面的行添加到它(更換密鑰名稱)

ssh-add ~/.ssh/YOUR_KEY

這將在啓動外殼

13

它可能使系統管理員在恐怖反衝,但痛苦這個問題(Windows)中後,我放棄了SSH,回到HTTPS。

首次將遠程存儲庫添加到Git時,請將SSH參考'[email protected]'替換爲HTTPS URL'https://<username>@bitbucket.org'。

你必須每次都輸入你的密碼,但特別是在Windows下,SSH不像* nix系列那樣普遍可用,我認爲這與SSH的頭痛相比是一個小麻煩。

+0

我在這上面花了幾個小時,看來只有_only_才能使用這個工作。我不喜歡在後臺不斷地運行這樣的軟件,特別是如果它集成到Windows資源管理器中,但似乎BitBucket不能像GitHub那樣以簡單的方式工作,我可以簡單地使用'ssh- keygen'生成公鑰並將其添加到我的GitHub帳戶。我已經接受BitBucket和Windows只是一個糟糕的組合,並已採取使用HTTPS。 –

0

在我的情況下,它解決了這個問題從目錄中

~/.ssh/id_rsa.pub 

添加SSH密鑰上bitbucket.org。我在網站上也將它命名爲id_rsa.pub。

在開始時,我添加了另一個我爲bitbucket創建的密鑰,並將其命名爲。第一次遠程操作起作用,但幾天後請求被拒絕。

0

在Windows中,@efesaid答案用於解決與ssh連接測試有關的問題。順便說一句,您可以添加-v來查看正在嘗試哪些鍵(按名稱)以及連接失敗的原因。

但是,當推送到bitbucket時,使用[email protected]:user/repo.git,似乎主機不是精確的bitbucket.org,所以我仍然獲得權限被拒絕的問題。我通過(重新)將密鑰命名爲id_rsa來解決這些問題(這是在ssh測試中嘗試的關鍵名稱)。

如果您有單個rsa密鑰,則可以使用此功能。對於多個鍵,或許在配置文件中的主機必須

bitbucket.org:username 

但我不相信這是理解過程

3

我的Linux(Ubuntu的)面臨着同樣的問題。

我解決了使用它設置在git

$ cat ~/.ssh/id_rsa.pub 

添加到位桶,並推升了資源庫:

git config --global user.name "Your Name" 
git config --global user.email [email protected] 

使用cat和SSH密鑰來bitbucket.org打印公鑰

git remote add origin [email protected]:<username>/your repository name.git 
git push -u origin --all 

就是這樣!

0

我認爲bitbucket指令是最好的。檢查是否安裝了SSH,如果不安裝它

[email protected]:~$ ssh -v 
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] 
      [-D [bind_address:]port] [-E log_file] [-e escape_char] 
      [-F configfile] [-I xxxxx] [-i identity_file] 
      [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec] 
      [-O ctl_cmd] [-o option] [-p port] 
      [-Q cipher | cipher-auth | mac | kex | key] 
      [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port] 
      [-w local_tun[:remote_tun]] [[email protected]]hostname [command] 

[email protected]:~$ ls -a ~/.ssh 
. .. google_compute_engine google_compute_engine.pub identity identity.pub known_hosts 

[email protected]:~$ ssh-keygen 
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/krasen/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/krasen/.ssh/id_rsa. 
Your public key has been saved in /home/krasen/.ssh/id_rsa.pub. 
The key fingerprint is: 
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx [email protected] 
The key's randomart image is: 
+--[ RSA 2048]----+ 
|    . | 
|   xx x | 
|   xxxxx | 
|  xxxxxxxxx | 
|  .xxxxxxxx | 
|  xxxxx  | 
|  xxxxxxxxxxxx| 
| xxxxxxxxxxxxx| 
|  xxxxxxxxxxx | 
+-----------------+                                 
[email protected]:~$ ls -la ~/.ssh                           
total 40 
drwx------ 2 krasen krasen 4096 Jun 29 14:30 . 
drwxr-xr-x 110 krasen krasen 4096 Jun 29 13:00 .. 
-rw------- 1 krasen krasen 1675 Mar 18 2015 google_compute_engine 
-rw-r--r-- 1 krasen krasen 409 Mar 18 2015 google_compute_engine.pub 
-rw------- 1 krasen krasen 1679 Jun 29 13:15 identity 
-rw-r--r-- 1 krasen krasen 409 Jun 29 13:15 identity.pub 
-rw------- 1 krasen krasen 1679 Jun 29 14:30 id_rsa 
-rw-r--r-- 1 krasen krasen 409 Jun 29 14:30 id_rsa.pub 
-rw-r--r-- 1 krasen krasen 4698 Jun 29 13:16 known_hosts 

[email protected]-Lenovo-Y50-70:~$ ssh-agent /bin/bash 

檢查是否啓動代理

[email protected]:~$ ps -e | grep [s]sh-agent 
26503 ?  00:00:00 ssh-agent 
[email protected]:~$ ssh-add ~/.ssh/id_rsa 
Identity added: /home/krasen/.ssh/id_rsa (/home/krasen/.ssh/id_rsa) 
[email protected]:~$ ssh-add -l 
2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx /home/krasen/.ssh/id_rsa (RSA) 
[email protected]:~$ cat ~/.ssh/id_rsa.pub 
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 

得到這個關鍵,它在到位桶設置

1

檢查exisiting添加爲關鍵SSH密鑰

ls -al ~/.ssh 

複製SSH密鑰

cat ~/.ssh/id_rsa.pub | pbcopy 

將複製的SSH密鑰添加到'Bitbucket Settings','Security','SSH Keys'。

7

在我的情況下新鮮的Ubuntu 16位機我是缺少在~/.ssh文件夾中的文件,以便什麼工作:

  1. 前往文件夾~/.ssh
  2. 運行ssh-keygen並命名文件即id_rsa
  3. 運行cat ~/.ssh/id_rsa.pub | xclip -sel clip
    如果你錯過xclip只是apt-get install xclip :)
  4. 轉到(在URL更改USERNAME t Ø您的用戶名到位桶:))https://bitbucket.org/account/user/USERNAME/ssh-keys/
  5. 點擊Add key並從剪貼板

魔術粘貼的關鍵 - 現在的工作:)

+0

問題是針對Mac OS,apt-get無關 – coto

+0

Ubuntu上的問題引導我進行此問答(爲什麼?請參閱標記),並且此問題涉及到Ubuntu用戶 - 因此我描述了我的經驗 - (因爲我不能100%說這個解決方案可以在其他操作系統中工作)。乾杯。 – abrasadera

+0

仍然不適合我(我正在使用Mac),任何想法? – anunixercoder

3

你可能會使用ssh的git的源URL。嘗試刪除ssh原始文件,就像這樣

git remote rm origin 

然後用HTTPS url添加新的來源,然後再次嘗試推送。

git remote add origin https://[email protected]/SOMETHING/SOMETHING.git 
git push -u origin master 

確保你粘貼你的url作爲來源的bitbucket。

0

我得到了一個類似的問題,我之前曾使用HTTPS訪問存儲庫,必須通過設置url來切換到SSH;

git remote set-url origin ssh://[email protected]/... 
0

這可能很明顯,但我花了相當多的時間。

檢查在目標上運行git remote -v

在我來說,當我有SSH密鑰完全成立,但該命令的輸出是:

origin [email protected]:USERNAME/REPOSITORY.git

(注意得到不是git

,而不是

origin [email protected]:USERNAME/REPOSITORY.git

再次,這是一個非常特別的情況,但一定要仔細檢查這一制度的字符串,如果你遇到了麻煩。

您可以用下面的命令解決這個問題:

git remote set-url origin [email protected]:USERNAME/REPOSITORY.git

0

建立混帳與git config --global user.name "My Name"git config --global user.email [email protected],我仍然有被拒絕的權限,(公鑰)錯誤麻煩之後。爲了解決這個問題,我首先生成與

ssh-keygen 

新的SSH令牌與

pbcopy < ~/.ssh/YOUR_KEY 

之後把它抄了,我去bitbucket.com將其添加爲我設置一個新的SSH密鑰。然後,我回到我的終端與

ssh-add ~/.ssh/YOUR_KEY. 

添加新鍵,我是有是我錯過了關鍵的ssh-add [key]命令的大問題。

0

確保您已在終端上切換到正確的用戶。

在我的情況下,root用戶不是在bitbucket設置面板上添加了ssh密鑰的用戶。使用sudo運行git可以讓它從root用戶運行,而我自己的用戶就是添加了密鑰的用戶。

相關問題