一.配置公鑰祕鑰
1.生成新的公鑰
注:郵箱是你git
地址的郵箱
$ ssh-keygen -t rsa -C "郵箱地址"
複製程式碼
如果需要有多個不同的ssh Key
的話,使用下面指定地址的命令。XXXX
為你取的名
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa.XXXX -C "郵箱地址"
複製程式碼
2.然後會提示輸入括號裡面的路徑(或者直接第三步,輸入密碼)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/youname/.ssh/id_rsa.XXXX):
複製程式碼
提示你輸入Key的名稱,按照括號給出的路徑輸入:/Users/youname/.ssh/id_rsa.XXXX
3.然後會讓你輸入密碼
輸入密碼和確認密碼。可以點選空格不設定密碼
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
複製程式碼
4.完成

二.上傳專案
1.獲取公鑰內容
$ cd .ssh
複製程式碼
$ more id_rsa.XXXX.pub
複製程式碼
複製包括前面ssh-rsa
和後面郵箱的全部內容,留著下步使用

2.新增SSH key
進入你們的git
伺服器連結,登入你的賬戶

填完後點選Add key
3.新建project或group


4.上傳
第一種方法,按照新新增的專案詳情頁的命令列指令操作

第二種方法,複製SSH地址

下載Sourcetree。下載連結
下載完成後點選新建...
---> 從URL克隆

源URL就是專案詳情頁的SSH地址,目標路徑在桌面建立一個空的資料夾,路徑放進來。名稱隨便

然後會處於載入中,等到克隆
按鈕可點就成功了。然後將你的專案貼上到新建的空資料夾,提交推送就可以了。
三.遇到的問題
如果在克隆倉庫失敗。左下角顯示這是一個無效的源路徑/URL。可能是由於多個SSH key造成的問題。可以試試這種方法解決。
1.建立SSH key的方法要使用最上面介紹的重新命名的方法
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa.XXXX -C "郵箱地址"
複製程式碼
2.在~/.ssh 目錄下新建一個config
檔案
$ touch ~/.ssh/config
複製程式碼

3.建立完成後開啟config
檔案
- 開啟
config
檔案所在的資料夾的命令
$ cd .ssh
$ open ./
複製程式碼
- 新增如下內容(根據自己情況新增,一般只新增你們gitlab伺服器的就行。其他沒有問題的不用新增)
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.github
user git
複製程式碼

4.檢查下是否正確
ssh -T git@github.com
複製程式碼
- 如果類似以下這種提示,就說明成功了。重新從URL克隆。
Welcome to GitLab, yourname
複製程式碼

- 如果提示以下這種錯誤,可以檢視下
Host git
和HostName
填寫是否是自己的git伺服器地址
Permission denied (publickey).
複製程式碼