git - Windows 真的只是自发地为 git 重新生成了我的 ssh key 吗?

标签 git ssh

多年来,每次我(或我公司中的其他人,似乎)尝试在 Windows 上使用 git 时,一切都会正常工作一段时间,直到突然它表现得好像它不再知道什么是 ssh key 了。它会停止提示我输入它的密码,而是要求我输入 git 服务器的密码。

ssh -v 为我指明了正确的方向,即 Windows 确实知道我的 ssh key ,但我的服务器似乎不接受它。

    $ 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:

查看我的服务器,我可以看到我的旧 Windows 公共(public) ssh key 已上传,但它不再与我机器上的那个匹配。像新计算机一样上传新 key 可以完全解决问题。

这是Windows偶尔会做的事情吗?为什么我的 key 会突然失效?我生成它可能不到一年前。

最佳答案

Windows 不会自行重置 ssh key 。

但是id_rsa/id_rsa.pub是默认的 ssh 私钥和公钥文件名。
这意味着如果任何其他应用程序生成一组新的 key ,这些 key 将被覆盖。

为了提高 ssh 设置的稳健性,一种可能的解决方法是:

  • %HOME%\.ssh 中重命名您的 key :
  • 添加 %HOME%\.ssh\config私钥的完整路径

  • 就像是:
    Host git.myhost.lan
      HostName git.myhost.lan
      User git
      IdentityFile C/Users/<yourLogin>/.ssh/git.myhost.lan
    

    那就试试ssh -Tv git.myhost.lan (不需要 git@ )

    关于git - Windows 真的只是自发地为 git 重新生成了我的 ssh key 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34590855/

    相关文章:

    git - Perforce 文件 ".perforce"的用途是什么?

    git - Youtrack 与 GIT 的集成级别(不是 github)

    git - 阻止将琐碎的 merge 推送到 git 服务器

    python-2.7 - SSH 窗口大小如何影响 paramiko

    java - 使用 SSHJ 时进行 Sudo 访问

    java - 使用 Java 将文件推送到现有的 GitLab 存储库?

    linux - 由于 401,无法执行 git pull

    git - Gerrit复制到gitlab失败

    linux - 为什么我的 bashrc 脚本不起作用?

    eclipse - 如何让eclipse记住ssh key 密码?