Git - ssh 密钥/IP 地址

发布于 2024-08-29 08:50:45 字数 317 浏览 1 评论 0原文

当我设置 Git 时,我是在使用 dsl 调制解调器时完成的,并且我的 IP 不是静态的,因此当我为 Git 生成 ssh 密钥时,它是基于该 IP 的。

当我分配的 IP 不是用于生成 ssh Git 密钥的 IP 时,我可以手动将 IP 地址更改为用于生成密钥的 IP 地址。我还有哪些其他选项可以绕过此步骤?动态域名解析?还有别的办法吗?

更新:

好的,所以密钥不受 IP 地址的影响。我做了一个 git Push origin master 并得到了一个无法识别的密钥错误,并认为这是 IP 地址。我将不得不尝试重新生成该错误。

When I set up Git, I did it while using a dsl modem, and my ip isn't static, so when I generated the ssh keys for Git, it was based on that ip.

When I'm assigned an ip other than the one used to generate the ssh Git keys, I can manually change the ip address to the one used to generate the keys. What are my other options to bypass this step? Dynamic DNS? Is there another way?

Update:

OK, so the key isn't influenced by the ip address. I did a git push origin master and got a not recognized key error and thought it was the ip address. I'll have to try and regenerate that error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听,心雨的声音 2024-09-05 08:50:45

SSH 密钥根本不使用您的 IP 地址来生成或识别。只有在要连接的计算机上设置某种 IP 过滤“仅允许来自特定 IP 地址的该用户进行 SSH 连接”时,才会出现问题。

唯一会遇到问题的情况是您要连接的计算机获得了新的 IP 地址,因为您的 SSH 客户端会注意到与您的known_hosts 文件 (~/.ssh/known_hosts) 相比的差异。这是为了防止中间人攻击。如果您预计 IP 会发生变化,那么您只需从known_hosts 文件中删除不再有效的行即可。

干杯。

SSH keys don't use your IP address for generation or identification at all. You'll only have problems if you set up some sort of IP filtering on the machine that you're connecting to, "Only allow SSH connections for this user from a certain IP address."

The only other time you would run into issues would be if the machine that you are connecting to got a new IP address, as you SSH client would notice differences compared to your known_hosts file (~/.ssh/known_hosts). This is to protect against man in the middle attacks. If you expected the IP to change, then you'd simply remove the no longer valid line from your known_hosts file.

Cheers.

向日葵 2024-09-05 08:50:45

我不确定在为 Git 创建 ssh 密钥时会考虑哪些因素,但您无需在每次 IP 更改时重新创建/编辑密钥。我在不同的计算机上创建了 3 或 4 个密钥以用于 Github。所有这些都是在动态 IP 上创建的,并且此后已使用多次,无需进行任何编辑。

I'm not sure what factors are taken into account when creating an ssh key for Git, but you won't need to recreate / edit your key each time your IP changes. I've created 3 or 4 keys on various computers for use with Github. All of them were created whilst on a dynamic IP and have been used many times since without the need to make any edits.

你丑哭了我 2024-09-05 08:50:45

我的问题应该更清楚,我没有使用 GitHub - 有问题的 Git 服务器是我自己的笔记本电脑,而不是 GitHub,所以服务器 IP 是根据调制解调器/路由器的突发奇想而改变的。

我为解决这个问题所做的就是为每个 ip 生成一个密钥对。然后,我将公钥添加到authorized_keys 文件中,为其他机器保留私钥的副本,并为每个IP 地址执行putty,以将密钥添加到putty 的缓存中。现在我只为调制解调器分配的每个 IP 执行此操作。很痛苦,但只需要一次,而不是一直改变 ip。

不过,我确实必须将 .git 目录中配置文件的远程部分更新为 IP 地址。我想我可以根据ip地址为远程部分中的每个ip地址添加一个单独的部分,再加上相应的分支部分。

这是我收到的错误:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:...
Connection abandoned.
fatal: The remote end hung up unexpectedly

我的设置是在 Windows 7 上,由 Cygwin(仅限 ssh)、msysgit 和 putty 套件组成。

I should have been clearer in my question, I wasn't using GitHub - the Git server in question is my own laptop, not GitHub, so it was the server ip that was changing on the whim of the modem/router.

What I did to resolve this was for each ip, to puttygen a key pair. I then added the public key to the authorized_keys file, kept a copy of the private key for my other machines and did a putty for each ip address to add the key to putty's cache. Now I just do this for each ip assigned by the modem. A pain, but only once rather than changing ips all the time.

I do have to update the remote section of the config file in the .git directory to the ip address though. I guess I could add a separate section for each ip address in the remote section based on the ip address, plus a corresponding branch section.

This was the error I was getting:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:...
Connection abandoned.
fatal: The remote end hung up unexpectedly

My setup is on Windows 7 and consists of Cygwin (ssh only), msysgit and the putty suite.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文