1. 程式人生 > >Mac 下source tree 與 gitlab 新增 ssh 金鑰

Mac 下source tree 與 gitlab 新增 ssh 金鑰

因為專案要使用 gitlab 來管理程式碼,所以還是使用 sourcetree 客戶端來管理自己的程式碼,因為個人不太喜歡命令列(了無生趣),主要是不太會用命令列,哈哈,平常都是圖形化介面工具用的比較多,可這次就犯難了,gitlab 上使用了 sshKey, 我用 sourcetree   git@xxxx 來客隆程式碼時反覆提示要輸入密碼,接著 url 無效,百度說是要在本地要配置 sshKey 私鑰,(gitlab 上已配置公鑰 之前已生成公鑰私鑰檔案(稍後會講生成方法)),想在sourcetree 中找到配置ssh 的選項,找了好多資料 如何在sourcetree 中配置 sshKey 私鑰,結果發現我的 sourcetree 跟百度上別人的 sourcetree(windows 下) 樣式都不一樣,根本就找不到配置sshKey 檔案的入口,我以為是我的版本與別人不一樣(版本為2.0破解版),問了別人結果別人的偏好設定裡面也沒有配置的選項,找了好久都找不到,我想著應該是 Mac 與 Windows 系統下版本的區別了。折騰了好久真是找不到方法,心裡真是拔涼拔涼的,程式碼都拉不下來還搞個毛啊,哈哈。。。。  (使用http 方式可以拉取 ,git@ 方式就不行),最終在終端生成sshKey 並新增私鑰 再將公鑰新增到 gitlab上

應該還有好多坑,這只是我遇到的一點而已,配置方法:

1 在普通使用者 進入 .ssh 檔案.(.ssh 檔案生成百度很多)       cd .ssh/    或 cd ~/.ssh

LELEdeMacBook-Pro:~ lele$ cd .ssh/

LELEdeMacBook-Pro:.ssh lele$ ls

known_hosts

LELEdeMacBook-Pro:.ssh lele$ man ssh-add

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ ssh-keygen -t rsa -C "your email"   // 你的郵箱

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/lele/.ssh/id_rsa): id_rsa1  // 給生成生成私鑰命名

Enter passphrase (empty for no passphrase):   // 設定輸入密碼

Enter same passphrase again: 

Your identification has been saved in id_rsa1. // 私鑰

Your public key has been saved in id_rsa1.pub. // 公鑰

The key fingerprint is:

SHA256:IL6L2NjBQDAAuYfD6NzTbR8VIc/fJl1coDUhzL3LYP8 [email protected]

The key's randomart image is:

+---[RSA 2048]----+

|B.       . +o.=o.|

|o.        +.o+.o.|

|o+  . .    oo  .o|

|*... . .   .+ + .|

|+o. o . S .. * = |

| = o o o .    *  |

|  o o . . .    . |

| = o .   .      E|

|o + .            |     

+----[SHA256]-----+

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ ls  // 檢視生成檔案

id_rsaid_rsa1id_rsa1.pubknown_hosts

LELEdeMacBook-Pro:.ssh lele$ cat id_rsa1.pub   // 開啟公鑰  複製公鑰貼上到 gitlab上設定 sshKey 的地方(可百度)

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIRPiN+aEeJ4ZAYshiKdDSv9tHovvmKCIai8uUc8RqxYo5BPJwN5NLH5FVKgIO12uj4PZl4q/QpXh9oaPVKJLZWTGh7aZc2lBmqS8CDLnFAniFnhYb5CABg+gQyFv71857UeV4QaO6sPas6jYFyeMgguEylzFUVz2dxsjonoGnPxA14YxG0k1bvkuQT1MEuwcyN17vOZYPOyh5xBfTJMYrqp3V875ju508SUgE+oFYXoJF/bMoUXPH+9D7YSTTqbocv55Su7z95/LMhp5RNX4MwMxJF9LdcLwTWvXuPucB6RbsRLqf9hy53/boLyphgc0UKpHNgPZTnCYRKJ8+hwrL [email protected]

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ 

LELEdeMacBook-Pro:.ssh lele$ ls

id_rsaid_rsa1id_rsa1.pubknown_hosts

LELEdeMacBook-Pro:.ssh lele$ ssh-add id_rsa1  // 新增私鑰

Enter passphrase for id_rsa1:  // 輸入密碼  此密碼為生成金鑰的時候設定的密碼 123456 方便好記 哈哈

Identity added: id_rsa1 (id_rsa1)

LELEdeMacBook-Pro:.ssh lele$ 

至此 sshKey 配置完成,開啟 source tree 克隆程式碼就 OK 了

/**

一段時間之後, 如果出現提交或拉取程式碼失敗,則需要重新在終端新增一下私鑰即可。

**/