简体   繁体   English

Windows 7上的Git不会通过ssh进行连接,除非已经向服务器打开了另一个ssh连接

[英]Git on Windows 7 does not connect via ssh unless another ssh connection is already open to the server

I have this really weird problem with git on Windows 7. I've installed msysgit, generated the ssh keys, and added id_rsa.pub to authorized_keys on my Ubuntu machine. 我在Windows 7上的git确实存在这个怪异的问题。我已经安装了msysgit,生成了ssh密钥,并将id_rsa.pub添加到了我的Ubuntu机器上的authorized_keys中。 If I open the git bash shell and attempt to ssh into the server it prompts for a password. 如果我打开git bash shell并尝试ssh进入服务器,则会提示输入密码。 However I expect it to use the key and not prompt for a password. 但是我希望它使用密钥,而不提示输入密码。 Now if I first open a ssh connection to the Ubuntu machine (via putty) and login, and then go back to the git bash shell the server accepts the connection with the key with no password. 现在,如果我首先打开与Ubuntu计算机的ssh连接(通过腻子)并登录,然后返回git bash shell,则服务器将接受不带密码的密钥连接。

Any ideas on what might be causing this connection weirdness? 关于什么可能导致此连接异常的任何想法?

Connect to server with no other ssh connections to server: 连接到服务器,没有其他到服务器的ssh连接:

$ ssh -v jeremy@192.168.1.248
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /c/Users/Jeremy/.ssh/config
debug1: Connecting to 192.168.1.248 [192.168.1.248] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Jeremy/.ssh/identity type -1
debug1: identity file /c/Users/Jeremy/.ssh/id_rsa type 1
debug1: identity file /c/Users/Jeremy/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-6ubuntu2
debug1: match: OpenSSH_5.1p1 Debian-6ubuntu2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<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: Host '192.168.1.248' is known and matches the RSA host key.
debug1: Found key in /c/Users/Jeremy/.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: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Users/Jeremy/.ssh/identity
debug1: Offering public key: /c/Users/Jeremy/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /c/Users/Jeremy/.ssh/id_dsa
debug1: Next authentication method: password
jeremy@192.168.1.248's password:

Connect to server after opening ssh connection to server through putty: 通过腻子打开与服务器的ssh连接后,连接到服务器:

$ ssh -v jeremy@192.168.1.248
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /c/Users/Jeremy/.ssh/config
debug1: Connecting to 192.168.1.248 [192.168.1.248] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Jeremy/.ssh/identity type -1
debug1: identity file /c/Users/Jeremy/.ssh/id_rsa type 1
debug1: identity file /c/Users/Jeremy/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-6ubuntu2
debug1: match: OpenSSH_5.1p1 Debian-6ubuntu2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<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: Host '192.168.1.248' is known and matches the RSA host key.
debug1: Found key in /c/Users/Jeremy/.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: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Users/Jeremy/.ssh/identity
debug1: Offering public key: /c/Users/Jeremy/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
Linux curious 2.6.31-23-generic #74-Ubuntu SMP Mon Feb 28 22:20:11 UTC 2011 x86_
64

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/

I ran into a similar problem with just trying to ssh into my server, not git related. 我试图通过ssh进入服务器而不是与git相关时遇到了类似的问题。 The actual issue was that my home directory on the server is encrypted. 实际的问题是服务器上的主目录已加密。 So unless the user is already logged in, the encrypted directory with the authorized_keys file is not mounted and thus not accessible by sshd. 因此,除非用户已经登录,否则不会挂载带有authorized_keys文件的加密目录,因此sshd无法访问该目录。 If the user already has a session open, the directory is mounted and ssh behaves as expected. 如果用户已经打开了会话,则目录将被挂载,并且ssh的行为符合预期。

Here is the official Ubuntu help for this situation: https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Troubleshooting 这是针对这种情况的Ubuntu官方帮助: https : //help.ubuntu.com/community/SSH/OpenSSH/Keys#Troubleshooting

Here is the solution I used: https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/362427/comments/12 这是我使用的解决方案: https : //bugs.launchpad.net/ubuntu/+source/openssh/+bug/362427/comments/12

And I got to both of these from this thread: https://superuser.com/questions/61057/ssh-with-authorized-keys-to-an-ubuntu-system-with-encrypted-homedir 我从这个线程获得了这两个信息: https : //superuser.com/questions/61057/ssh-with-authorized-keys-to-an-ubuntu-system-with-encrypted-homedir

My immediate suspicion is that it's looking for an authentication agent, and failing to find one, then failing to run ssh-askpass to unlock your private key for some reason. 我的直接怀疑是,它正在寻找身份验证代理,但找不到一个,然后由于某种原因而无法运行ssh-askpass来解锁您的私钥。 But if you start Putty, it starts the agent and sets it up properly, then the command line ssh can use it to get your private key. 但是,如果您启动Putty,它将启动代理并正确设置它,然后命令行ssh可以使用它来获取您的私钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM