【问题标题】:Git on Windows 7 does not connect via ssh unless another ssh connection is already open to the serverWindows 7 上的 Git 不会通过 ssh 连接,除非另一个 ssh 连接已经打开到服务器
【发布时间】:2011-07-28 02:29:57
【问题描述】:

我在 Windows 7 上遇到了一个非常奇怪的 git 问题。我已经安装了 msysgit,生成了 ssh 密钥,并将 id_rsa.pub 添加到了我的 Ubuntu 机器上的 authorized_keys 中。如果我打开 git bash shell 并尝试 ssh 进入服务器,它会提示输入密码。但是我希望它使用密钥而不提示输入密码。现在,如果我首先打开到 Ubuntu 机器的 ssh 连接(通过 putty)并登录,然后返回到 git bash shell,服务器会接受没有密码的密钥连接。

关于什么可能导致这种连接怪异的任何想法?

在没有其他 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:

通过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/

【问题讨论】:

    标签: git windows-7 ssh putty


    【解决方案1】:

    我的直接怀疑是它正在寻找身份验证代理,但找不到,然后由于某种原因未能运行ssh-askpass 来解锁您的私钥。但是如果你启动 Putty,它会启动代理并正确设置它,然后命令行ssh 可以使用它来获取你的私钥。

    【讨论】:

      【解决方案2】:

      我只是尝试通过 ssh 进入我的服务器时遇到了类似的问题,与 git 无关。实际问题是我在服务器上的主目录是加密的。因此,除非用户已经登录,否则带有 authorized_keys 文件的加密目录不会被挂载,因此 sshd 无法访问。如果用户已经打开了一个会话,则挂载该目录并且 ssh 会按预期运行。

      这是针对这种情况的官方 Ubuntu 帮助: https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Troubleshooting

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

      我从这个线程中得到了这两个: https://superuser.com/questions/61057/ssh-with-authorized-keys-to-an-ubuntu-system-with-encrypted-homedir

      【讨论】:

      • 感谢您的回答!这就是问题所在。我从未想到过加密的主文件夹。
      猜你喜欢
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      相关资源
      最近更新 更多