V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
whatCanIDoForYou
V2EX  ›  程序员

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

  •  
  •   whatCanIDoForYou · 2020-08-05 16:56:29 +08:00 · 2449 次点击
    这是一个创建于 1331 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题概述

    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 端口开放
    21 条回复    2020-08-06 14:08:08 +08:00
    kaifang
        1
    kaifang  
       2020-08-05 17:00:20 +08:00
    ssh user@ip -p port ?
    zhongjun96
        2
    zhongjun96  
       2020-08-05 17:03:46 +08:00
    ssh [email protected] -p 8888
    heyjei
        3
    heyjei  
       2020-08-05 17:05:27 +08:00
    这个不是应改 git remote 的 url 嘛?和 ssh 的 config 有什么关系
    SoloCompany
        4
    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
        5
    sherlockwhite  
       2020-08-06 09:50:25 +08:00
    ssh://git@ip:8888/*/*.git
    remote_url 加上 ssh
    whatCanIDoForYou
        6
    whatCanIDoForYou  
    OP
       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
        7
    whatCanIDoForYou  
    OP
       2020-08-06 09:56:21 +08:00
    @sherlockwhite #5 这句 git 该怎么写?? 能否指正下
    这样吗。。。。
    " git remote_url ssh://git@ip:8888/*/*.git " ?
    应该不是。。
    查了下 好像没有这个语法 git remote_url
    whatCanIDoForYou
        8
    whatCanIDoForYou  
    OP
       2020-08-06 09:58:39 +08:00
    @heyjei #3 查过 git remote -v 发现 ssh 中确实有端口号
    sherlockwhite
        9
    sherlockwhite  
       2020-08-06 10:12:22 +08:00
    @whatCanIDoForYou
    git clone ssh://git@ip:8888/*/*.git
    这样能明白吗,ssh 不是默认 22 端口 url 要加上 ssh
    sherlockwhite
        10
    sherlockwhite  
       2020-08-06 10:12:59 +08:00
    你直接把项目删了重新 clone 不可以么
    sherlockwhite
        11
    sherlockwhite  
       2020-08-06 10:14:07 +08:00   ❤️ 1
    要是改.git/config 那么麻烦的话
    或者试试 git remote add ssh://git@ip:8888/*/*.git
    whatCanIDoForYou
        12
    whatCanIDoForYou  
    OP
       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
        13
    sherlockwhite  
       2020-08-06 10:29:04 +08:00
    @whatCanIDoForYou ssh 的公私钥配置了么
    Songxwn
        15
    Songxwn  
       2020-08-06 10:46:21 +08:00
    内网改什么非标准端口,也没有安全问题
    nightwitch
        16
    nightwitch  
       2020-08-06 10:48:11 +08:00
    在你的项目目录里的.git/config 文件改成这样就可以了
    sherlockwhite
        17
    sherlockwhite  
       2020-08-06 11:53:14 +08:00
    @whatCanIDoForYou 本地配置了么,本地怎么配置的?
    sherlockwhite
        18
    sherlockwhite  
       2020-08-06 11:53:36 +08:00
    @Songxwn 问题不在改端口。
    whatCanIDoForYou
        19
    whatCanIDoForYou  
    OP
       2020-08-06 12:00:19 +08:00
    @Songxwn #15 运维人员搞的 我也不好多说什么。。最 sao 的是其他同事好像都没有这样 难道是因为他们都用 http ??? (因为之前和我一起入职的那个人不会配 SSH )。。。

    @nightwitch #16 图片裂了。。
    @sherlockwhite #17 本地怎么配置。。。 我是 git client 脚本自己生成的( ssh-keygen -t rsa -C "[email protected]") 然后我配置到 gitlab 中。
    sherlockwhite
        20
    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)


    试试
    whatCanIDoForYou
        21
    whatCanIDoForYou  
    OP
       2020-08-06 14:08:08 +08:00
    @sherlockwhite #20 能加老哥一个 V 吗 本人的 v :dng5Nzk5NDMzNzA=

    执行 ssh-add id_rsa(secret key) 出错 语法好像 syntax error near unexpected token `('
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3001 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:57 · PVG 22:57 · LAX 07:57 · JFK 10:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.