gitlab ssh clone问题解决

公司搭建的gitlab,通过http协议可以clone:

[[email protected] gitlab]$ git clone http://gitlab.test.mycompany.com/dev_group/test_project1.git
Cloning into ‘test_project1‘...
Username for ‘http://gitlab.test.mycompany.com‘: sisi
Password for ‘http://[email protected]‘:
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 11 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.

但是用ssh clone就会失败

[[email protected] ssh]$ git clone [email protected]:dev_group/test_project1.git
Cloning into ‘test_project1‘...
The authenticity of host ‘gitlab.test.mycompany.com (123.56.11.231)‘ can‘t be established.
RSA key fingerprint is 5d:62:8d:b7:d7:51:03:87:ea:65:ce:35:6c:ee:95:7a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘gitlab.test.mycompany.com,123.56.11.231‘ (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.

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

解决方案
(1)修改/etc/ssh/sshd_config文件
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
(2)改权限及公钥
#chmod 700 /root/.ssh
#chmod 644 /root/.ssh/authorized_keys
并把本地主机的pub公钥放到/root/.ssh/authorized_keys
(3)重启sshd
service restart

但是之后用ip测试连接成功,用域名则失败
[[email protected] ssh]$ ssh -T [email protected]
Welcome to GitLab, sisi!
[[email protected] ssh]$ ssh -T [email protected]
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

git clone的结果也是一样的

[[email protected] ssh]$ git clone [email protected]:dev_group/test_project1.git
Cloning into ‘test_project1‘...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[[email protected] ssh]$ git clone [email protected]:dev_group/test_project1.git
Cloning into ‘test_project1‘...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 11 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (11/11), done.
[[email protected] ssh]$

用IP可以克隆,用域名还不行

那么问题在于域名是否正确解析为正确的ip

[[email protected] .ssh]$ host gitlab.test.mycompany.com
gitlab.test.mycompany.com has address 123.56.11.231
[[email protected] ssh]$ ping gitlab.test.mycompany.com
PING gitlab.test.mycompany.com (172.16.181.60) 56(84) bytes of dat
不同方式获取的IP不一致,是导致ssh用域名访问不行的原因

执行git  clone时连接的服务器地址放在.ssh/known_hosts中,从其中可以看出域名被解析成123.56.11.231,

即与host命令查到的ip一致,都是错误的

解决方案:

(1)删除 .ssh/known_hosts中错误的域名ip记录

(2)在/etc/hosts增加域名与正确ip的对应

[[email protected] .ssh]$ sudo vi /etc/hosts
增加一行
172.16.181.60 gitlab.test.mycompany.com

再测试成功如下:

[[email protected] ssh]$ git clone [email protected]:dev_group/test_project1.git
Cloning into ‘test_project1‘...
The authenticity of host ‘gitlab.test.mycompany.com (172.16.181.60)‘ can‘t be established.
RSA key fingerprint is ba:ec:d0:b3:b3:1e:39:10:fc:b2:ac:3d:41:ff:d1:50.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘gitlab.test.mycompany.com,172.16.181.60‘ (RSA) to the list of known hosts.
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 11 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (11/11), done.
[[email protected] ssh]$ ls
test_project1

原文地址:https://www.cnblogs.com/newalan/p/9286458.html

时间: 2024-08-09 12:23:03

gitlab ssh clone问题解决的相关文章

【docker】【Gitlab】gitlab中clone项目时,IP地址是一串数字(内网Gitlab的IP地址不正确)的问题解决

首次在内网搭建Gitlab环境,在成功后在Gitlab上新建了一个项目. 然而在IDEA上clone项目时发现,项目地址如下: git@0096ce63c43f:root/jump.git 或者这样 http://0096ce63c43f/root/jump.git 然而在setting中看到的IP地址却是虚拟机的IP地址: 但是此处是无法改变的IP地址,也就是我在IDEA进行clone项目时,还是这一串: 而这样进行Clone操作,这种IP是识别不了的 OK,问题描述完了,现在来说说解决方法:

window下 配置gitlab ssh非端口22端口

git config --global user.name "jack" git config --global user.email "[email protected]" Create a new repository mkdir fromai_cn cd fromai_cn git init touch README.md git add README.md git commit -m "first commit" git remote a

git乌龟http/https以及ssh clone的秘钥配置永久免密码登录设置

1.安装 安装Git 安装TortoiseGit 乌龟客户端 首先下载安装一个git客户端这个就不多说了基本就是next一直到底 安装后首次新建一个项目project在git服务器上 2.配置 1.注册用户,让git知道你是谁,在于提交代码的时候,知道是哪个家伙提交的!git config --global user.name  "chen1932490299"    用户名是git服务器上配置的谁填谁git config --global user.email "19324

持续集成 Jenkins +Gitlab + SSH 自动发布 HTML 代码

一.整体流程 二.Jenkins 配置 2.1.首先安装插件 Gitlab Hook Plugin GitLab Plugin Publish Over SSH 2.2.配置目标服务器 系统管理 ---> 系统设置 ---> Publish over SSH 如果不想使用密钥认证登陆,也可以使用 账户密码登陆. 2.3.创建 job 我们创建一个自由风格的 job,配置好 git 源,这里也可以配置无密钥登陆,我这里使用账户密码. 创建触发器,用于自动构建,我们需要把其中的 url 添加到我们

gitlab ssh 免密登录

打开本地git   使用 ssh-keygen 工具 输入命令  ssh-keygen -t rsa -C '你的邮箱账号' 接下来输入密码 确认密码 找到目录 找到公钥 在 gitlab 用户设置  ssh密钥  填写公钥 点击 生成 key 修改 tortoiseGit ssh客户端 然后先用 命令 拉取一次 要输入 yes 克隆成功 原文地址:https://www.cnblogs.com/qin1993/p/11400829.html

[转载] Ubuntu root不能ssh登陆问题解决

今天安装了Ubuntu  Server 14.04   发现配置了root密码后 竟然不能ssh登陆,但是su root正常!  why? 原来新版本里面sshd_config里面有了限制 #vim /etc/ssh/sshd_config # Authentication:LoginGraceTime 120#PermitRootLogin without-password    #找到这里,把它注释PermitRootLogin yes                  #改为yes  然后

gitlab ssh key

认证的ssh key [[email protected] .ssh]# ls id_rsa  id_rsa.pub  known_hosts [[email protected] .ssh]# cat id_rsa.pub  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQXqp00YxAQ5cwo6Ashv+TC9DKcg9qyppdlo41E7MLvVm9NXxnS8nB3OOZGleMzkQZ2UD4LljaG8Bc/wp80KRe0YngtXtdk0oZ

关于gitlab的一个问题解决

这两天折腾一个关于gitlab的问题,搞得比较焦头烂额.不过经过折腾,最终还是成功了. 当面对着一个问题,并且看到还没被解决的时候,感觉很不舒服: 努力折腾之后,解决之后,也会身体轻松.或许工程师天生就是"不解决问题不舒服斯基".这是习惯,以后要改.这里简要记录一下. 一.产生的问题描述: 前两天同事自己在gitlab上面创建了一个仓库,http://121.201.13.32:9000/sbzhou/tsd-collector.git,由于所有peoject都基本是统一的前缀 htt

windows下如何生成gitlab ssh公钥

1.查看是否已经有了ssh密钥:cd ~/.ssh如果没有密钥则不会有此文件夹,有则备份删除2.生存密钥: $ ssh-keygen -t rsa -C "你的邮箱"按3个回车,密码为空. Your identification has been saved in /home/tekkub/.ssh/id_rsa.Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.The key fingerprint is:-