1魁淳、生成SSH-Key
$ ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/id_rsa_github
$ ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/id_rsa_gitlab
2盆驹、查看公鑰
$ cat ~/.ssh/id_rsa_github.pub
$ cat ~/.ssh/id_rsa_gitlab.pub
3琅催、將公鑰內(nèi)容復(fù)制粘貼至gitlab/github SSH公鑰
4居凶、添加私鑰
$ ssh-add ~/.ssh/id_rsa_gitlab
$ ssh-add ~/.ssh/id_rsa_github
5、添加配置文件
//進(jìn)入ssh目錄
$ cd ~/.ssh
//新建config文件
$ touch config
6藤抡、編輯config文件
//打開ssh文件
$ open ~/.ssh
打開config文件進(jìn)行如下編輯
# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
#用于自動(dòng)添加ssh
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_gitlab
IdentityFile ~/.ssh/id_rsa_github
# 配置文件參數(shù)
# Host : Host可以看作是一個(gè)你要識(shí)別的模式侠碧,對(duì)識(shí)別的模式,進(jìn)行配置對(duì)應(yīng)的的主機(jī)名和ssh文件
# HostName : 要登錄主機(jī)的主機(jī)名
# IdentityFile : 指明上面User對(duì)應(yīng)的identityFile路徑
編輯好后 command + s
保存下缠黍,這樣就OK了
7弄兜、測(cè)試
$ ssh -T git@github.com
第一次鏈接會(huì)出現(xiàn)提示Are you sure you want to continue connecting (yes/no)? 輸入yes回車。
提示下面的就代表成功了瓷式!
Hi riceFun! You've successfully authenticated, but GitHub does not provide shell access.