由于名称解析错误导致与ssh的Github连接失败

时间:2017-08-20 00:08:58

标签: git github ssh

我已经使用我的github帐户注册了一个ssh密钥。 键位于

~/.ssh/id_rsa_github_snail
~/.ssh/id_rsa_github_snail.pub

我有一个repo,其中远程URL配置为使用ssh:

$ git remote -v
origin  git@github.com:danielsank/pong.git (fetch)
origin  git@github.com:danielsank/pong.git (push)

但是,当我尝试从公司计算机上推送时,我收到以下错误消息

danielsank@snail:~/src/pong$ git push
ssh: connect to host github.com.<company>.<name>.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

请注意,由于某种原因,ssh尝试连接到github.com.<company>.<name>.com而不是github.com

我在/etc/resolve.conf中发现了以下可疑位:

# It is common within <company> to lookup hostnames with a dot in it like for an
# example '<machine>.<site>'. We set 'options ndots:2' so that such hostnames
# get tried first with the <company> search domains appended. Without this such
# queries might be tried first against an external DNS resolver.
options ndots:2

可以 ping github.com。

我尝试将网址设置为git@github.com.:danielsank/pong.git。 在这样做之后,当我尝试推送时,我被要求接受来自github的主机指纹,但随后出现了不同的错误:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我认为这是因为回购品名称中的额外点。

有一种解决此配置的好方法吗? 我有点意外的是,如果没有附加公司名称,该决议不会再次尝试...

1 个答案:

答案 0 :(得分:1)

您似乎在/etc/resolve.conf或公司名称服务器中有奇怪的DNS设置。要防止这些DNS设置将.<company>.<name>.com附加到带有点的主机名,请在主机名末尾添加一个点:

ping github.com. # <- note the dot!
git remote set-url origin git@github.com.:danielsank/pong.git

关于第二个问题 - 如果您想使用具有非标准名称的密钥,您可以在~/.ssh/config中为主机分配密钥:

Host github.com github.com.
    User git
    IdentityFile ~/.ssh/id_rsa_github_snail