Mac OS 配置多個ssh-key

1、創(chuàng)建config文件

cd .ssh
touch config

2、創(chuàng)建ssh-key

ssh-keygen -t rsa -f ~/.ssh/id_rsa.別名 -C “郵箱地址“
示例:
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C “xxx@xxx.com“
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C “xxx@xxx.com“

ssh-key文件已經(jīng)生成到指定路徑,接下來需要對他們進(jìn)行配置

3、配置

# gitlab
Host gitlab.xxx.com
HostName gitlab.xxx.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_xxx_id-rsa

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id-rsa

# 配置文件參數(shù)
# Host : Host可以看作是一個你要識別的模式,對識別的模式,進(jìn)行配置對應(yīng)的的主機名和ssh文件
# HostName : 要登錄主機的主機名
# User : 登錄名
# IdentityFile : 指明上面User對應(yīng)的identityFile路徑

Host是別名,如果只是為了區(qū)分github、gitlab等,為了方便使用,建議和HostName一致,這樣在clone git的時候不用考慮修改hostname。

4、通過別名來使用

ssh -T git@gitlab.xxx.com 
返回:Welcome to Gitlab, xxx!

5、設(shè)置和去除全局用戶名和郵箱

去除:
git config --global --unset user.name
git config --global --unset user.email

設(shè)置:
git config –-global user.email "xx@xx.com"  

git config --global user.name "xxx" 

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容