簡體   English   中英

git 在 Windows 上使用 PuTTY 推送失敗(致命:遠端意外掛斷)

[英]git push using PuTTY on Windows fails (fatal: The remote end hung up unexpectedly)

為准備好進行我的第一個git push興奮,我在我的 cygwin 環境中為PuTTY創建了一個別名:

alias ssh="/cygdrive/c/PROGRA~2/putty/PUTTY.EXE"

然后調用(當然是在我的工作目錄中),正如git 社區手冊第 47 頁中所述:

git push ssh://mylinuxserver/~winwin/gitrepo master:master

我的興奮並沒有持續很長時間,因為它立即因致命錯誤而失敗:

error: cannot run ssh: No such file or directory
fatal: unable to fork

考慮到我能夠成功運行,從相同的命令行和 shell 實例ssh winwin@mylinuxserver收到此錯誤消息,我感到非常驚訝。

知道為什么會發生這種情況以及如何解決這個問題嗎?

更新 I:感謝本指南,我發現 PUTTY.EXE 不是在 git 中使用的正確 exe。 相反,應該使用PLINK.EXE

該指南還暗示應該使用名為 GIT_SSH 的環境變量讓 git 知道如何發揮作用。 所以我:

~/sb/ws> export GIT_SSH=/cygdrive/c/PROGRA~2/putty/PLINK.EXE
~/sb/ws> git push ssh://mylinuxserver/~winwin/gitrepo master:master

現在我收到一個不同的錯誤:

fatal: The remote end hung up unexpectedly

我認為這個進展是正確的,但我仍然不知道如何解決這個問題。 任何想法將不勝感激。

更新二:仍在嘗試解決這個謎團。 這一次我懷疑由於git push不會在任何地方提示輸入用戶名+密碼,身份驗證必須在密鑰中......所以,我根據這個 howto仔細檢查了sshd配置。 我發現唯一需要更改的是取消注釋/etc/ssh/sshd_config中的HostKey /etc/ssh/ssh_host_dsa_key行並重新啟動服務service sshd restart 在那之后的第一次, $GIT_SSH確實提示確認服務器的 dss 密鑰指紋,我確認將密鑰存儲在緩存中,但是......問題仍然存在:

fatal: The remote end hung up unexpectedly

額外的想法?

(PuTTY 的注冊表現在包含同一服務器的兩個鍵: rsa2@22:mylinuxserverdss@22:mylinuxserver 。嗯……我不確定這是什么意思)

更多診斷信息:鍵入$GIT_SSH -v產生:

~/sb/ws> $GIT_SSH -v
Looking up host "mylinuxserver"
Connecting to 192.168.1.2 port 22
Server version: SSH-2.0-OpenSSH_4.2
We claim version: SSH-2.0-PuTTY_Release_0.60
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-dss 1024 c8:77:42:4f:76:29:56:4c:ea:b0:11:6a:a6:3c:6a:f7
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
login as: winwin
winwin@mylinuxserver's password:
Sent password
Access granted
Opened channel for session
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
Last login: Wed Jul 13 21:41:12 2011 from winmachine

你能發現任何可疑的東西嗎?

到達那里:到目前為止,我的情況的最佳指南: Git, SSH, PuTTY

見解:

  1. $GIT_SSH -agent必須運行一次
  2. PAGEANT.EXE 必須在后台運行(並通過其系統托盤圖標添加私鑰!)
  3. 必須使用 PUTTYGEN.EXE 生成公鑰/私鑰對
  4. dss 不是強制性的,rsa 就足夠了。
  5. 更多 (除非$GIT_SSH -2 -C -i C:\\Users\\winwin\\SSH\\private.ppk在沒有密碼提示的情況下成功,否則即使嘗試git push也沒有意義......)

在將公鑰從 PuTTY 密鑰生成器復制並粘貼到/home/winwin/.ssh/authorized_keys中的mylinuxserver后,會出現一條新消息以響應上述見解 #5 中的命令:

Server refused our key

這是一個好兆頭...... :) 我想我正在解開這個謎團。

更新三:在 sshd 服務器上的/etc/ssh/sshd_config中將StrictModes更改為no后,我成功地使用$GIT_SSH -2 -C -i C:\\Users\\winwin\\SSH\\private.ppk 不過,它仍然提示輸入用戶名(但不提示輸入密碼)。

git push ssh://mylinuxserver/~winwin/gitrepo master:master繼續失敗 - 帶有相同的錯誤消息:

fatal: The remote end hung up unexpectedly

瘋了吧。

更新 IV: PLINK 的-l username參數是關鍵。 我設法使git push登錄成功,通過創建 1 行 shell 腳本/cygdrive/c/PROGRA~2/putty/PLINK.EXE -l winwin $*並將整個腳本的路徑導出到$GIT_SSH ,但是“遠端仍然意外掛斷”。

這就是我在客戶端(Windows/PuTTY)方面得到的:

~/sb/ws> git push ssh://mylinuxserver/~winwin/gitrepo master:master
Environment:
  USER=winwin
  LOGNAME=winwin
  HOME=/home/winwin
  PATH=/usr/local/bin:/bin:/usr/bin
  MAIL=/var/mail/winwin
  SHELL=/bin/bash
  SSH_CLIENT=192.168.1.8 50951 22
  SSH_CONNECTION=192.168.1.8 50951 192.168.14.2 22
bash: mylinuxserver: command not found
fatal: The remote end hung up unexpectedly

這就是我在服務器端(Linux/sshd)端得到的:

debug1: sshd version OpenSSH_4.2p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Address already in use.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 4 out 4 newsock 4 pipe -1 sock 7
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.1.8 port 50951
debug1: Client protocol version 2.0; client software version PuTTY_Release_0.60
debug1: no match: PuTTY_Release_0.60
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.2
debug1: permanently_set_uid: 74/74
debug1: list_hostkey_types: ssh-rsa,ssh-dss
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: client->server aes256-ctr hmac-sha1 none
debug1: kex: server->client aes256-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received
debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done

debug1: userauth-request for user winwin service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "winwin"
debug1: PAM: setting PAM_RHOST to "win7client"
debug1: PAM: setting PAM_TTY to "ssh"
Failed none for winwin from 192.168.1.8 port 50951 ssh2
debug1: userauth-request for user winwin service ssh-connection method publickey
debug1: attempt 1 failures 1
debug1: test whether pkalg/pkblob are acceptable
debug1: temporarily_use_uid: 513/513 (e=0/0)
debug1: trying public key file /home/winwin/.ssh/authorized_keys
debug1: matching key found: file /home/winwin/.ssh/authorized_keys, line 1
Found matching RSA key: bd:a6:4a:6a:04:43:8d:60:d9:bf:66:de:51:13:83:66
debug1: restore_uid: 0/0
Postponed publickey for winwin from 192.168.1.8 port 50951 ssh2
debug1: userauth-request for user winwin service ssh-connection method publickey
debug1: attempt 2 failures 1
debug1: temporarily_use_uid: 513/513 (e=0/0)
debug1: trying public key file /home/winwin/.ssh/authorized_keys
debug1: matching key found: file /home/winwin/.ssh/authorized_keys, line 1
Found matching RSA key: bd:a6:4a:6a:04:43:8d:60:d9:bf:66:de:51:13:83:66
debug1: restore_uid: 0/0
debug1: ssh_rsa_verify: signature correct
debug1: do_pam_account: called
Accepted publickey for winwin from 192.168.1.8 port 50951 ssh2
debug1: monitor_child_preauth: winwin has been authenticated by privileged process
Accepted publickey for winwin from 192.168.1.8 port 50951 ssh2
debug1: PAM: reinitializing credentials
debug1: permanently_set_uid: 513/513
debug1: Entering interactive session for SSH2.
debug1: server_init_dispatch_20
debug1: server_input_channel_open: ctype session rchan 256 win 16384 max 16384
debug1: input_session_request
debug1: channel 0: new [server-session]
debug1: session_new: init
debug1: session_new: session 0
debug1: session_open: channel 0
debug1: session_open: session 0: link with channel 0
debug1: server_input_channel_open: confirm session
debug1: server_input_channel_req: channel 0 request exec reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req exec
debug1: Received SIGCHLD.
debug1: session_by_pid: pid 3441
debug1: session_exit_message: session 0 channel 0 pid 3441
debug1: session_exit_message: release channel 0
debug1: session_close: session 0 pid 3441
debug1: channel 0: free: server-session, nchannels 1

Connection closed by 192.168.1.8
debug1: do_cleanup
debug1: PAM: cleanup
Closing connection to 192.168.1.8
debug1: PAM: cleanup

需要最后的線索...

  1. bash: mylinuxserver: command not found是什么意思?
  2. 什么是git push試圖運行?
  3. 哪個命令?
  4. 在客戶端還是 SSH 服務器上?

使用 plink? 您可能必須重新創建為 putty 創建的密鑰。

http://www.xinotes.org/notes/note/156/

我覺得通過 Putty 是造成所有這些問題的原因,但不清楚為什么這是必要的 - 如果您使用的是 cygwin,那么您已經內置了 ssh。

我通過 cygwin 使用 git 而不是 ssh 沒有問題。 可能是更好的路線? 是否有理由加入膩子,或者它是在某個地方的指南中推薦的東西?

我從來沒有成功讓gitPuTTY一起工作。 對我而言,進一步的時間投資似乎不能證明投資回報率是合理的,所以我放棄了。

暫無
暫無

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

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