侧边栏壁纸
博主头像
DOKI SEKAI博主等级

行动起来,活在当下

  • 累计撰写 114 篇文章
  • 累计创建 38 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

修改 GitLab SSH 配置

君
2025-01-06 / 0 评论 / 0 点赞 / 6 阅读 / 3023 字

1. 修改 GitLab SSH 配置

首先,登录到 GitLab 服务器并修改 SSH 配置文件。

  1. 打开 SSH 配置文件 /etc/ssh/sshd_config

    sudo nano /etc/ssh/sshd_config
    
  2. 找到 Port 22 这一行,修改为 Port 36522

    Port 36522
    
  3. 保存并关闭文件。

2. 允许新端口通过防火墙

如果你的服务器启用了防火墙,需要确保允许端口 36522 的流量。

对于 ufw(Uncomplicated Firewall):

sudo ufw allow 36522/tcp
sudo ufw reload

对于 firewalld

sudo firewall-cmd --permanent --add-port=36522/tcp
sudo firewall-cmd --reload

3. 重启 SSH 服务

修改完配置文件后,重启 SSH 服务来应用新的端口设置。

sudo systemctl restart sshd

4. 配置 GitLab 使用新端口

确保 GitLab 配置了正确的 SSH 端口。通常,GitLab 会自动使用系统的 SSH 配置,但你可以在 gitlab.rb 文件中设置自定义的 SSH 端口。

  1. 编辑 GitLab 配置文件:

    sudo nano /etc/gitlab/gitlab.rb
    
  2. 找到 gitlab_rails['gitlab_shell_ssh_port'] 配置项,修改为 36522

    gitlab_rails['gitlab_shell_ssh_port'] = 36522
    
  3. 保存并关闭文件。

  4. 重新配置 GitLab:

    sudo gitlab-ctl reconfigure
    

5. 更新客户端配置

如果你通过 SSH 连接到 GitLab,需要在本地的 SSH 客户端中指定新的端口。例如:

git clone ssh://[email protected]:36522/your-repository.git

或者在 ~/.ssh/config 文件中为 GitLab 配置新的端口:

Host gitlab.com
  HostName your.gitlab.com
  Port 36522
  User git

完成这些步骤后,GitLab 将通过新的 SSH 端口 36522 进行通信。

0

评论区