美文网首页
gitLab ssh 配置

gitLab ssh 配置

作者: mayday2024 | 来源:发表于2024-07-03 12:09 被阅读0次

配置这个通常是config配置错误 搞好了 也可以用sourceTree 上便用gitlab

  1. 生成SSH密钥
    使用您的邮箱生成SSH密钥对:

sh
复制代码

ssh-keygen -t rsa -b 4096 -C "我的邮箱@qq.com"

默认位置通常是可以接受的(~/.ssh/id_rsa)。

  1. 添加SSH密钥到SSH代理
    如果您使用SSH代理(如ssh-agent),可以将私钥添加到代理中:

启动SSH代理:

sh
复制代码

eval "$(ssh-agent -s)"

添加私钥到代理:

sh
复制代码

ssh-add ~/.ssh/id_rsa
  1. 将公钥添加到GitLab
    复制公钥内容:

sh
复制代码

cat ~/.ssh/id_rsa.pub

登录到您的GitLab服务器(http://gitlab.你的域名.com),转到“设置” > “SSH Keys”。

在“Key”文本框中粘贴您的公钥内容,然后点击“Add key”按钮。

  1. 配置SSH客户端
    编辑您的SSH配置文件(~/.ssh/config):

sh
复制代码

nano ~/.ssh/config

添加以下内容 关键在这里:

Host gitlab.你的域名.com
    Hostname gitlab.你的域名.com
    User git
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa
  1. 测试SSH连接
    在终端中测试与GitLab服务器的SSH连接:
ssh -T git@gitlab.你的域名.com

如果配置正确,您应该看到类似以下的信息:

Welcome to GitLab, @your_username!
  1. 克隆GitLab项目
    使用SSH URL克隆项目:
    复制代码
git clone git@gitlab.你的域名.com:ios/Reallegend.git

相关文章

网友评论

      本文标题:gitLab ssh 配置

      本文链接:https://www.haomeiwen.com/subject/bebbcjtx.html