簡體   English   中英

Windows 上的 Git 不要求輸入 SSH 密鑰密碼或使用 SSH 密鑰

[英]Git on Windows not asking for SSH key password, or using SSH Key

根本問題是我從來沒有看到提示輸入我的 SSH-Key 密碼、SSH-Agent 或否。 因此,這就像我輸入了錯誤的密碼並默認假裝我沒有鑰匙一樣。

這發生在多台計算機上。 不久前我設置了我的 ssh 密鑰,一切都很好,但每隔一段時間我會做一個 git push (通常在重新啟動我的計算機后),我會被要求提供我的 git 源服務器的密碼而不是我的 ssh 密鑰的密碼。 由於我的源服務器沒有密碼,這使我無法推送更改。

有時重新啟動后它會自行解決,有時則不會。 通常我會做很多亂七八糟的猜測,其中一個最終解決了問題,但我目前不記得哪些有效,哪些無效。

解決這個問題的正確方法是什么? 實際問題是什么? 我的 SSH 密鑰被鎖定了嗎? 是否某些 Windows 進程未正確啟動? 路徑變量是否被吃掉了? 我對 Windows 不太了解(通常我是在 linux 上開發的),所以我在這里特別茫然。

編輯:第一個答案提到了 ssh-agent。 一些谷歌搜索讓我到了這里:

https://help.github.com/articles/working-with-ssh-key-passphrases/#platform-windows

其中解釋了如何設置 ssh-agent 以自動啟動並了解 Windows 中的密鑰。 (我什至不知道您可以在 Windows 中使用 bash 配置文件)。

這沒有幫助。

我的 git bash 現在說“身份添加:/c/Users/{{ME}}/.ssh/id_rsa”它不要求我輸入我的密鑰密碼,我仍然無法推送到我的源服務器(它要求一個服務器密碼,仍然)。

我可以確認我的 ssh 密鑰確實位於代理正在查找的位置。 我還可以確認密鑰已添加: ssh-add -l顯示單個密鑰,來自我的密鑰存儲位置。

編輯:將 GIT_SSH 設置為指向 ssh 可執行文件的環境變量也沒有任何作用,但無論如何它都是一個長鏡頭。

編輯: ssh git@git.myhost.com 輸出:

$ ssh -v git@git.myhost.lan
OpenSSH_6.6.1, OpenSSL 1.0.1i 6 Aug 2014
debug1: Reading configuration data /c/Users/eschjen/.ssh/config
debug1: /c/Users/eschjen/.ssh/config line 1: Applying options for git.myhost
.lan
debug1: Connecting to git.myhost.lan [10.116.22.40] port 22.
debug1: Connection established.
debug1: identity file /c/Users/eschjen/.ssh/id_rsa type 1
debug1: identity file /c/Users/eschjen/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA ae:81:77:0d:1c:8e:6a:aa:a8:69:36:1b:e4:ca:33:ee
debug1: Host 'git.myhost.lan' is known and matches the RSA host key.
debug1: Found key in /c/Users/eschjen/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi
c,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/eschjen/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi
c,password
debug1: Next authentication method: password
git@git.myhost.lan's password:

輸出屏幕幫助我確定 ssh 密鑰正在被使用,但被服務器拒絕。 我發現我的服務器知道的 ssh 密鑰與我的機器擁有的 ssh 密鑰不匹配,盡管不到一個月前一切正常。 我重新添加了我擁有的 ssh 密鑰,並且能夠推送我的更改。

任何人都知道在所有這些過程中如何重新生成 ssh 密鑰(我很確定我沒有明確地這樣做)?

您需要告訴您的計算機在重新啟動系統后再次添加密鑰。 大多數情況下,這是通過ssh-agent

添加身份是不夠的。 在您的C:\\Users\\{{username}}\\.ssh目錄中應該有一個名為config (無擴展名)的文件。

您可以定義用於給定主機的密鑰,如下所示:

Host myhost.name.com
 IdentityFile ~/.ssh/my_keyfile_name

正確配置的結果是輸入密碼請求:

Enter passphrase for key '/c/Users/{{username}}/.ssh/my_keyfile_name':

Edit1:您可以通過添加 -v 參數來檢索 ssh 的詳細輸出。 真實世界示例(已替換主機名):

λ ssh -v igor@myhost.at
OpenSSH_6.6.1, OpenSSL 1.0.1m 19 Mar 2015
debug1: Reading configuration data /c/Users/Igor/.ssh/config
debug1: /c/Users/Igor/.ssh/config line 4: Applying options for myhost.at
debug1: Connecting to myhost.at [192.168.2.1] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Igor/.ssh/myhost-server type -1
debug1: identity file /c/Users/Igor/.ssh/myhost-server-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze5
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze5 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 67:3f:96:7b:6a:68:55:89:a8:30:a9:ed:67:ef:40:a4
debug1: Host 'myhost.at' is known and matches the RSA host key.
debug1: Found key in /c/Users/Igor/.ssh/known_hosts:3
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Igor/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /c/Users/Igor/.ssh/myhost-server
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/c/Users/Igor/.ssh/myhost-server':

我認為這將有很大幫助。 向請求此信息的 OP 添加了評論。

我浪費了幾個小時試圖解決同樣的問題 - 即使選美沒有運行,SSH 也不會要求我的密鑰對的密碼。

SSH 使用不同的密鑰格式(SSH-1 和 SSH-2),更重要的是,如果它們是 SSH-2 格式,則拒絕讀取 RSA 密鑰。 使用 Puttygen 生成密鑰對,然后將其轉換為 SSH-1 格式以保存在 .ssh\\id_rsa 中,為我解決了這個問題。

  1. 生成密鑰對
  2. 用一個有意義的名字保存它(比如 Basement-Computer.ppk)
  3. 將文件導出為 OpenSSH 格式並使用名稱id_rsa (無擴展名)保存

膩子

Git clone 現在會要求輸入密碼(或者至少對我來說是這樣)。 Google 關於設置 Git 存儲庫https://cloud.google.com/source-repositories/docs/authentication#ssh 的說明忽略了關鍵的第三步。

暫無
暫無

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

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