个别服务器出现git clone提示需要密码或者无法连接的问题
因为代码仓库地址变更, 昨天在更新git remote url时, 发现一个诡异的问题: 在部分服务器上进行下拉代码时提示如下错误(更新remote url之后)。
我重新执行克隆操作也是同样的错误:
git clone ssh://[email protected]/ibg/ibg_test.git (git clone [email protected]:ibg/ibg_test.git “[email protected]:ibg/ibg_test.git” == “ssh://[email protected]/ibg/ibg_test.git” ) ,在某些机器上可以正确拉取到代码,某些机器上拉取时提示
Initialized empty Git repository in /home/test/.ssh/ibg_test/.git/
[email protected]'s password:
因为某些机器是可以正常拉取代码, 根据现象初步认为, 远端的gitlab 仓库地址是没有问题. 而问题出现在git客户端上。
在不能正确拉取代码的机器上执行如下操作:
删除~/.ssh/known_hosts后,我们重新再次 git clone ssh://[email protected]/ibg/ibg_test.git (git clone [email protected]:ibg/ibg_test.git )
initialized empty Git repository in /home/test/.ssh/ibg_test/.git/
The authenticity of host '[gitlab.youxin.com]:22222 ([10.3.3.50]:22222)' can't be established.
RSA key fingerprint is c0:32:7a:00:1d:6f:c4:a0:d1:04:db:20:0b:c2:56:6c.
Are you sure you want to continue connecting (yes/no)?
在可以正确拉取代码的机器上重复执行如上操作:
initialized empty Git repository in /home/test/.ssh/ibg_test/.git/
The authenticity of host '[gitlab.youxin.com]([10.3.3.50])' can't be established.
RSA key fingerprint is c0:32:7a:00:1d:6f:c4:a0:d1:04:db:20:0b:c2:56:6c.
Are you sure you want to continue connecting (yes/no)?
区别在于, 一个请求是22222 端口。 但是正常可以拉取代码的机器没有显示22222, 应该是默认的ssh 22端口。 这时候进一步分析,为什么git 访问ssh 协议的代码仓库地址时, 默认使用22222呢。
我们需要检查2个地方的配置。
1) ~/.ssh/config 是否有配置
2) /etc/ssh/ssh_config 是否有配置port 端口号 (如果配置port端口号, 这样 ssh client 默认链接服务器的 端口号)
经过确认,我们的/etc/ssh/ssh_config 配置了port 22222. 为了不影响其他用户使用到该配置,所以在当前决定修改 ~/.ssh/config 配置,这样只会影响当前用户。
添加的配置如下
Host *
Port 22
增加保存后, 再次执行 git clone ssh://[email protected]/ibg/ibg_test.git 已经可以正常拉取代码了。
问题总结:
我们拉取的地址是 ssh://[email protected]/ibg/ibg_test.git , 其实应该是 ssh://[email protected]:22/ibg/ibg_test.git (22是端口号) 但因为某些机器上设定了ssh 默认服务器链接配置的端口号不是22 , 而是其他端口号例如 22222. 那么我们链接的实际地址 ssh://[email protected]:22222/ibg/ibg_test.git, 这样地址不同,就导致我们无法正确拉取代码。
所以这里地址隐藏了端口号,因为默认的端口号可能会导致意想不到的错误。 所以我们这里
ssh://[email protected]/ibg/ibg_test.git == git clone ssh://[email protected]:22/ibg/ibg_test.git
此篇文章已被阅读1106 次