[不懂就问] gitlab 客户端使用相关问题

2020-08-05 16:56:29 +08:00
 whatCanIDoForYou

问题概述

  1. 公司自己搭建的 gitlab 服务器把 gitlab 服务端口改为非 22 暂定 8888
  2. 之前此台服务器 22 端口是开放的 我拉取代码什么的 通过配置 SSH 认证 然后拉取 一切 OK
  3. 今天 突然运维人员将服务器 22 端口关闭。导致我一脸懵逼的 pull 不下来代码( ssh 默认端口是 22 吧。。)。。。 刚开始以为自己的 ssh 秘钥出现问题。问题如下:

通过孜孜不倦的查阅(百度 Boy 上线) 教程基本如下:

问题解决:

  1. 找到 C:\Users\你自己用户.ssh 文件夹下的 config 文件(没有后缀,没有就新建)进去添加几行: Host ip User XXXX.XXX.com Hostname IP PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 8888

然后就可以把 ssh 的端口指向这个 8888 了。我以为解决了 然后又去 pull 。。。出现如下图:

懵逼。。! 然后又去 Google 。。 说把 你 git 安装目录下的 C:\Program Files\Git\etc\ssh\ 下这个文件 sshd_config

最大连接数等等注解去掉 数值加大。我也试了,出现错误继续如上图所示!。

最终大法:

迫不得已,去看了看同事的配置发现他是通过 http.. 我改了改项目中.git/config 配置文件,,,,解决 OK 。。 就是想来问问 我自己怎么能够通过 SSH 连接到服务器呢。。

有一个小小的要求:

  1. 服务器端口 22 不会开放的前提。别说让管理员把 22 端口开放
2472 次点击
所在节点    程序员
21 条回复
kaifang
2020-08-05 17:00:20 +08:00
ssh user@ip -p port ?
zhongjun96
2020-08-05 17:03:46 +08:00
ssh xx@192.xxx.xx.xx -p 8888
heyjei
2020-08-05 17:05:27 +08:00
这个不是应改 git remote 的 url 嘛?和 ssh 的 config 有什么关系
SoloCompany
2020-08-05 18:03:47 +08:00
https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols

这是通常的 ssh remote url
git@server:path/to/project.git

难道不能用指定端口的 url 吗
ssh://git@server:port/path/to/project.git
sherlockwhite
2020-08-06 09:50:25 +08:00
ssh://git@ip:8888/*/*.git
remote_url 加上 ssh
whatCanIDoForYou
2020-08-06 09:51:35 +08:00
@kaifang #1
@zhongjun96 #2
@SoloCompany #4
ssh://git@server:port/path/to/project.git (更改项目中.git/config 配置文中 url 配置 )指定端口后 还是异常,,,
之前有试过
然后又查了下 remote -v
![]( https://imgkr2.cn-bj.ufileos.com/9efdb4ff-06cc-4ffc-85e7-48cad16f6546.png?UCloudPublicKey=TOKEN_8d8b72be-579a-4e83-bfd0-5f6ce1546f13&Signature=LYW09jQdMbxs24ncb0Ad8JHVC5Y%253D&Expires=1596763930)

查了下 配置 发现就是我想要的端口 但是拉取的时候还是访问 22 能具体指导下,,, ( git 新手)

![]( https://imgkr2.cn-bj.ufileos.com/3326080c-e4e7-422f-b1ba-162e1e2322f8.png?UCloudPublicKey=TOKEN_8d8b72be-579a-4e83-bfd0-5f6ce1546f13&Signature=bk2AYi8uUgkF%252BbLGAQv1OQ0cR1o%253D&Expires=1596765044)
whatCanIDoForYou
2020-08-06 09:56:21 +08:00
@sherlockwhite #5 这句 git 该怎么写?? 能否指正下
这样吗。。。。
" git remote_url ssh://git@ip:8888/*/*.git " ?
应该不是。。
查了下 好像没有这个语法 git remote_url
whatCanIDoForYou
2020-08-06 09:58:39 +08:00
@heyjei #3 查过 git remote -v 发现 ssh 中确实有端口号
sherlockwhite
2020-08-06 10:12:22 +08:00
@whatCanIDoForYou
git clone ssh://git@ip:8888/*/*.git
这样能明白吗,ssh 不是默认 22 端口 url 要加上 ssh
sherlockwhite
2020-08-06 10:12:59 +08:00
你直接把项目删了重新 clone 不可以么
sherlockwhite
2020-08-06 10:14:07 +08:00
要是改.git/config 那么麻烦的话
或者试试 git remote add ssh://git@ip:8888/*/*.git
whatCanIDoForYou
2020-08-06 10:25:11 +08:00
@sherlockwhite #11 十分谢谢指导
可是通过
此句:git clone ssh://git@ip:8888/*/*.git
![]( https://imgkr2.cn-bj.ufileos.com/5196378a-6950-419a-84a3-d509251adbc3.png?UCloudPublicKey=TOKEN_8d8b72be-579a-4e83-bfd0-5f6ce1546f13&Signature=ySQ79RDepFt5IYyl5yMsbY3R6yI%253D&Expires=1596766948)

更改 .git/config 如果继续使用 ssh 还是不行 ( git remote add ssh://git@ip:8888/*/*.git ) 这个效果也是类似重新指向一个新的 url 吧。。但是我使用 http 后就解决。。。 所以就来问问 SSH 咋回事。。
sherlockwhite
2020-08-06 10:29:04 +08:00
@whatCanIDoForYou ssh 的公私钥配置了么
whatCanIDoForYou
2020-08-06 10:37:00 +08:00
Songxwn
2020-08-06 10:46:21 +08:00
内网改什么非标准端口,也没有安全问题
nightwitch
2020-08-06 10:48:11 +08:00
在你的项目目录里的.git/config 文件改成这样就可以了
sherlockwhite
2020-08-06 11:53:14 +08:00
@whatCanIDoForYou 本地配置了么,本地怎么配置的?
sherlockwhite
2020-08-06 11:53:36 +08:00
@Songxwn 问题不在改端口。
whatCanIDoForYou
2020-08-06 12:00:19 +08:00
@Songxwn #15 运维人员搞的 我也不好多说什么。。最 sao 的是其他同事好像都没有这样 难道是因为他们都用 http ??? (因为之前和我一起入职的那个人不会配 SSH )。。。

@nightwitch #16 图片裂了。。
@sherlockwhite #17 本地怎么配置。。。 我是 git client 脚本自己生成的( ssh-keygen -t rsa -C "lxxx@Xxxxx.com") 然后我配置到 gitlab 中。
sherlockwhite
2020-08-06 12:02:43 +08:00
@whatCanIDoForYou Windows 还是 macOS ?

Windows 下打开 git bash
$ ssh-agent bash
$ ssh-add id_rsa(secret key)

macOS 下应该直接
$ ssh-add -K id_rsa(secret key)


试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/695898

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX