有時咱們在開發的過程當中,須要把代碼提交到不一樣的gitlab倉庫裏面,好比:公司的gitlab、GitHub等其餘git倉庫;在代碼提交的時候都須要驗證本機的SSH Keys;git
在使用 ssh-keygen -t rsa -C "youremal@emal.com"這個命令是默認都是生成到~/.ssh/id_rsa和~/.ssh/id_rsa.pub裏面,若是已存在會覆蓋的;github
那麼若是是本地有多個SSH Keys呢?vim
若是你有多個gitlab帳號dom
執行命令ssh
ssh-keygen -t rsa -C "emal1@163.com" //這個郵箱必定要是你對應的gitlab綁定的郵箱
複製代碼
執行是會出現如下詢問:ide
Generating public/private rsa key pair.
//默認的輸出文件就是根目錄下的.ssh/id_rsa 你須要從新指定一個文件名
//如:.ssh/id_rsa_emal1 文件名如何定義自行決定
Enter file in which to save the key (/Users/a58/.ssh/id_rsa): /Users/a58/.ssh/id_rsa_emal1
/Users/a58/.ssh/id_rsa_58 already exists.
//已存在是否覆蓋
Overwrite (y/n)? y
//設置密碼 可直接跳過
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/a58/.ssh/id_rsa_emal1.
Your public key has been saved in /Users/a58/.ssh/id_rsa_emal1.pub.
The key fingerprint is:
SHA256:aNZ0rCQP3xI1jmcvv9H9GKDjuRhE6VMVcLDeLKi53dE emal1@163.com
The key's randomart image is:
+---[RSA 2048]----+
| =o+. |
| * = |
| o B O |
| % @ + |
| + S = = |
| o + o * o . |
| o . + E o .|
| o = + o o.|
| . o =.. . .|
+----[SHA256]-----+
複製代碼
直接vim或者cat輸出pub公鑰文件:gitlab
cat /Users/a58/.ssh/id_rsa_emal1.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC12HyuAvMnRzQK24SXtJF7v5BL3lsH6ab1/NzYO/Q7whOTndqsS59/ZCqK/HK5TiwJkoEH+l2tB9o8a+1De5ri/9a7zLVIEST/ig79LiCcoIengSLX8jX37dq6pchBfKSdukXBsGJnrxKVsnVZScY5Bozx8LlhPYOuFuxZ8yW/2nxVAVaa1aIa8W4ZDA3rxBsdClh5GjT8dWHvfZtb8w8bFdjKSywvf4+GeIW0gjrRgmpkRmwaiCRam2dmnOS0vWNy+ZhkIeiMR0DqSpbT5Zeb81NVuvN3oXAornUR5GjN5wyKR2UsXLIJ4TvccYS+8EOKItM1FBX3oyGeQHO8qeWL emal1@163.com
複製代碼
拷貝文件裏面的內容添加到你對應的gitlab的ssh keys裏面spa
在你本地的~/.ssh/ 下面新建config文件 文件裏面添加以下內容3d
# emal1 gitlab
# 添加你Git倉庫地址的域名 如:github
Host emal1.gitlab.com
#填寫你gitlab綁定的郵箱
User emal1@163.com
PreferredAuthentications publickey
#對應你剛剛生成的公鑰文件
IdentityFile ~/.ssh/id_rsa_emal1
複製代碼
OK以上你都完成了以後那邊也就完成了git的提交的配置了。code