Linux 服务器配置 SSH 连接 GitLab 仓库

目标:让 Linux 服务器通过 SSH 访问公司 GitLab 仓库(免密码 clone / push)。 核心流程只有 4 步: 1️⃣ 生成 SSH key2️⃣ 把公钥添加到 GitLab 3️⃣ 测试 SSH 连接4️⃣ 使用 SSH clone ⭐ 一、在 Linux 服务器生成 SSH 密钥 推荐 ed25519(更安全、更快) ssh-keygen -t ed25519 -C "your_email" 一路回车即可。 生成后默认文件: ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub ⭐ 二、查看公钥内容 cat ~/.ssh/id_ed25519.pub 复制整行输出。 ⭐ 三、把公钥添加到 GitLab 进入 GitLab: 头像 → Preferences → SSH Keys 或直接: https://gitlab.xxx.com/-/profile/keys 粘贴公钥 → Add key。 ⭐ 四、测试 SSH 连接 ssh -T git@gitlab.xxx.com 第一次会提示: Are you sure you want to continue connecting? 输入: ...

June 1, 2025 · 2 min · 223 words · Hao