配置這個通常是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