簡體   English   中英

使用與 Windows 主機共享的存儲庫在“git fetch”上的 Ubuntu VM 上突然出現“權限被拒絕(公鑰)”

[英]Suddenly getting “Permission denied (publickey)” on Ubuntu VM on “git fetch” using repository shared with Windows host

我有一台 Windows 10 筆記本電腦。 我在那台筆記本電腦上運行了一個 Ubuntu 18.04 VM。 我在筆記本電腦上有幾十個 git 存儲庫,遠程是我們的 Intranet BitBucket 實例。 我使用共享文件夾在 Linux VM 上引用了完全相同的存儲庫。 這個設置已經運行了很長一段時間。 我可以在 Windows 主機或 Linux VM 上執行所有相同的 git 操作,並且它們都可以正常工作,並且這些操作的任何更改都會反映在其他操作系統上。

所有這些存儲庫都使用 ssh 克隆,並在 BitBucket 服務器中注冊了密鑰對。 同樣,這在很長一段時間內都運行良好。

就在今天,我嘗試在 Linux VM 上進行一些操作,例如“git fetch”,但失敗如下:

git@.....com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

我從 shell 和 Eclipse EGit 測試了這個,結果相同。

然后我回到 Windows 主機,到同一個存儲庫(請記住,我使用 VM 上的共享文件夾指向相同的存儲庫),並做了同樣的事情,它工作得很好。

我們的防火牆團隊在最近幾個月對我們的防火牆進行了一些更改,而且他們不傾向於宣布更改,所以這是一個未知數。

我不確定我能得到什么信息來診斷這個。

更新

設置GIT_SSH_COMMAND="ssh -vvv"非常有用。 這告訴我:

debug1: Offering public key: RSA SHA256:...
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: <myhome>/.ssh/id_dsa
debug3: no such identity: <myhome>/.ssh/id_dsa: No such file or directory
debug1: Trying private key: <myhome>/.ssh/id_ecdsa
debug3: no such identity: <myhome>/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: <myhome>/.ssh/id_ed25519
debug3: no such identity: <myhome>/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.

很長一段時間以來,我的密鑰對在 ~/.ssh 中作為“id_rsa”和“id_rsa.pub”。 這是在尋找“dsa”,而不是“rsa”。 我在網上看到一些 arguments 應該使用哪個,但我認為 rsa 對此仍然有效。 目前還不清楚這里應該做什么。

更新

當我添加“IdentityFile”時,它仍然不起作用,但它清楚地注意到了新設置並做了一些不同的事情。 現在,當我比較帶有和不帶有該設置的文本 output 時,我發現即使沒有“IdentityFile”設置,它仍然在找到“id_rsa”文件,我只是沒有注意到它。

我猜以下省略的 output 顯示了詳細的“git fetch” output 沒有和使用新設置的區別:

*** withoutidentity.txt 2020-08-13 06:29:56.662638000 -0700
--- withidentity.txt    2020-08-13 06:30:10.786638000 -0700
***************
*** 10,27 ****
  debug1: identity file <myhome>/.ssh/id_rsa type 0
  debug1: key_load_public: No such file or directory
  debug1: identity file <myhome>/.ssh/id_rsa-cert type -1
- debug1: key_load_public: No such file or directory
- debug1: identity file <myhome>/.ssh/id_dsa type -1
- debug1: key_load_public: No such file or directory
- debug1: identity file <myhome>/.ssh/id_dsa-cert type -1
- debug1: key_load_public: No such file or directory
- debug1: identity file <myhome>/.ssh/id_ecdsa type -1
- debug1: key_load_public: No such file or directory
- debug1: identity file <myhome>/.ssh/id_ecdsa-cert type -1
- debug1: key_load_public: No such file or directory
- debug1: identity file <myhome>/.ssh/id_ed25519 type -1
- debug1: key_load_public: No such file or directory
- debug1: identity file <myhome>/.ssh/id_ed25519-cert type -1
  debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
  debug1: Remote protocol version 2.0, remote software version APACHE-SSHD-2.3.0
  debug1: no match: APACHE-SSHD-2.3.0
--- 10,15 ----
***************
*** 90,100 ****
  debug1: SSH2_MSG_NEWKEYS received
  debug2: set_newkeys: mode 0
  debug1: rekey after 4294967296 blocks
! debug2: key: <myhome>/.ssh/id_rsa (0x55b82d8f2390), agent
! debug2: key: davmichaelkarr@gmail.com (0x55b82d8f7c50), agent
! debug2: key: <myhome>/.ssh/id_dsa ((nil))
! debug2: key: <myhome>/.ssh/id_ecdsa ((nil))
! debug2: key: <myhome>/.ssh/id_ed25519 ((nil))
  debug3: send packet: type 5
  debug3: receive packet: type 6
  debug2: service_accept: ssh-userauth
--- 78,85 ----
  debug1: SSH2_MSG_NEWKEYS received
  debug2: set_newkeys: mode 0
  debug1: rekey after 4294967296 blocks
! debug2: key: <myhome>/.ssh/id_rsa (0x562f96fec330), explicit, agent
! debug2: key: davmichaelkarr@gmail.com (0x562f96ff1b30), agent
  debug3: send packet: type 5
  debug3: receive packet: type 6
  debug2: service_accept: ssh-userauth
***************
*** 123,134 ****
  debug2: we sent a publickey packet, wait for reply
  debug3: receive packet: type 51
  debug1: Authentications that can continue: publickey
- debug1: Trying private key: <myhome>/.ssh/id_dsa
- debug3: no such identity: <myhome>/.ssh/id_dsa: No such file or directory
- debug1: Trying private key: <myhome>/.ssh/id_ecdsa
- debug3: no such identity: <myhome>/.ssh/id_ecdsa: No such file or directory
- debug1: Trying private key: <myhome>/.ssh/id_ed25519
- debug3: no such identity: <myhome>/.ssh/id_ed25519: No such file or directory
  debug2: we did not send a packet, disable method
  debug1: No more authentication methods to try.
  git@codecloud.web.att.com: Permission denied (publickey).
--- 108,113 ----

感覺不確定性太多,無法給出准確的答案。 您是否嘗試通過運行帶有詳細 output 的 ssh 來獲取額外的調試信息? 它可能暗示到底出了什么問題:

嘗試這個:

GIT_SSH_COMMAND="ssh -vvv" git clone or git fetch

更新:

好的,所以 ssh 詳細 output 告訴它它確實嘗試了幾個密鑰,但是沒有找到它們,因此無法驗證您的身份。

你的 .ssh/config 中有什么東西嗎? 我通常將哪個密鑰與哪個存儲庫一起使用。 例如在我的機器上,我有一個這樣的條目:

$ cat .ssh/config
Host gitlab.com
    Hostname gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa-gitlab

它告訴 ssh 使用這個確切的密鑰進行身份驗證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM