将 github 的 IP 地址设置为来源 url

Setting the IP address of github as the origin url

我的服务器有 DNS 问题,无法找到 "Github.com"。我必须改用 Github 的 IP 地址。但是当我尝试使用这样的 IP 地址时:

git remote set-url origin http://192.30.253.113/foo/bar.git

当我尝试推送到原点时,发生了这种情况:

git push origin master

fatal: unable to access 'https://192.30.253.113/foo/bar.git/': SSL: certificate subject name (github.com) does not match target host name '192.30.253.113'

Git pull 不起作用,因为 Git 验证 SSL 证书并检查主机名是否与证书中的名称匹配。在您的情况下,IP 未包含在证书中,因此您会收到此错误。

一个选项可能是禁用 SSL(如 中所述),但是,这将允许攻击者对您的连接进行中间人攻击。

而不是禁用 SSL 验证,为什么不将 github.com 添加到 /etc/hosts(参见 https://ubuntuforums.org/showthread.php?t=3407),这样 SSL 证书验证仍然有效。