gpt4 book ai didi

windows - Windows 上的 Git 不要求 SSH key 密码,或使用 SSH key

转载 作者:可可西里 更新时间:2023-11-01 13:55:59 27 4
gpt4 key购买 nike

根本的问题是我从来没有看到输入我的 SSH-Key 密码、SSH-Agent 或否的提示。因此,这就像我输入了错误的密码并默认假装我没有 key 。

这发生在多台计算机上。我不久前设置了我的 ssh key ,一切都很好,但我经常会执行 git push(通常在重新启动计算机后)并且我会被要求提供我的 git 源服务器的密码而不是我的 ssh key 的密码。由于我的原始服务器没有密码,这使我无法推送更改。

有时重启后会自行解决,有时不会。通常我会做很多乱七八糟的猜测,其中一个最终解决了问题,但我现在不记得哪些有效,哪些无效。

解决此问题的正确方法是什么?实际问题是什么?我的 SSH key 被锁定了吗?是否某些 Windows 进程未正确启动?路径变量是否被吃掉?我不太了解windows(通常我在linux上开发),所以我在这里很茫然。

编辑: 第一个答案提到了 ssh-agent。一些谷歌搜索让我来到这里:

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

其中解释了如何设置 ssh-agent 以自动启动并了解您在 Windows 中的 key 。 (我什至不知道您可以在 Windows 中使用 bash 配置文件)。

这没有帮助。

我的 git bash 现在说“Identity added:/c/Users/{{ME}}/.ssh/id_rsa” 它不要求我输入 key 密码,我仍然无法推送到我的源服务器(它要求对于服务器密码,仍然)。

我可以确认我的 ssh key 确实存在于代理正在寻找的地方。我还可以确认 key 已添加:ssh-add -l 显示单个 key ,来 self 的 key 存储位置。

编辑:将 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 key ,但被服务器拒绝。我发现我的服务器知道的 ssh key 与我的机器拥有的 ssh key 不匹配,尽管不到一个月前一切正常。我重新添加了我拥有的 ssh key ,并且能够推送我的更改。

有人知道在所有这些过程中如何重新生成 ssh key (我很确定我没有明确地这样做)吗?

最佳答案

仅添加标识是不够的。在您的 C:\Users\{{username}}\.ssh 目录中应该有一个名为 config(无扩展名)的文件。

您可以像这样定义用于给定主机的 key :

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 添加评论。

关于windows - Windows 上的 Git 不要求 SSH key 密码,或使用 SSH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336952/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com