配置这个通常是config配置错误 搞好了 也可以用sourceTree 上便用gitlab
- 生成SSH密钥
使用您的邮箱生成SSH密钥对:
sh
复制代码
ssh-keygen -t rsa -b 4096 -C "我的邮箱@qq.com"
默认位置通常是可以接受的(~/.ssh/id_rsa)。
- 添加SSH密钥到SSH代理
如果您使用SSH代理(如ssh-agent),可以将私钥添加到代理中:
启动SSH代理:
sh
复制代码
eval "$(ssh-agent -s)"
添加私钥到代理:
sh
复制代码
ssh-add ~/.ssh/id_rsa
- 将公钥添加到GitLab
复制公钥内容:
sh
复制代码
cat ~/.ssh/id_rsa.pub
登录到您的GitLab服务器(http://gitlab.你的域名.com),转到“设置” > “SSH Keys”。
在“Key”文本框中粘贴您的公钥内容,然后点击“Add key”按钮。
- 配置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
- 测试SSH连接
在终端中测试与GitLab服务器的SSH连接:
ssh -T git@gitlab.你的域名.com
如果配置正确,您应该看到类似以下的信息:
Welcome to GitLab, @your_username!
- 克隆GitLab项目
使用SSH URL克隆项目:
复制代码
git clone git@gitlab.你的域名.com:ios/Reallegend.git