1瘸味、打開(kāi)終端輸入如下命令:
ssh-keygen -t rsa -C "xxxx@qq.com"
其中1845...為注冊(cè)github的郵箱
2、出現(xiàn)如下提示時(shí)按回車鍵確認(rèn)
Enter file in which to save the key (/Users/xxxx/.ssh/id_rsa):
3酱讶、出現(xiàn)如下提示時(shí)交掏,輸入密碼:
Enter passphrase (empty for no passphrase):?
4沈条、出現(xiàn)如下提示時(shí)酣难,再次輸入密碼:
Enter same passphrase again:?
5、出現(xiàn)如下提示時(shí)紊撕,表明秘鑰生成成功
Your identification has been saved in /Users/liuboying/.ssh/id_rsa.
Your public key has been saved in /Users/liuboying/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pOE18kCMOhl56E1gg45EFcUO9evX6tODe6VuHbqHa5g xxx@qq.com
6罢荡、進(jìn)入~/.ssh目錄,打開(kāi)id_rsa.pub文件
cd ~/.ssh
vim id_rsa
將id_rsa.pub文件的內(nèi)容copy出來(lái)
7、打開(kāi)github的個(gè)人設(shè)置頁(yè)柠傍,點(diǎn)擊左側(cè)的SSH and GPG keys麸俘,點(diǎn)擊“New ssh key”按鈕,并將copy的id_rsa文件內(nèi)容寫(xiě)入輸入框后保存惧笛,如下圖
8从媚、配置多個(gè)賬號(hào)
cd ~/.ssh
vim config
并在編輯器中輸入一下內(nèi)容:
Host github.con
HostName github.com
User liuboying
IdentityFile /Users/xxxx/.ssh/id_rsa_github_qq (注意此處為id_rsa_github_qq的絕對(duì)路徑。)
如果有多個(gè)賬號(hào)患整,則將以上4條內(nèi)容增加在config文件中拜效,并將相應(yīng)信息改成其他賬號(hào)對(duì)應(yīng)的信息。(經(jīng)測(cè)試各谚,在我的電腦上IdentityFile路徑中的文件名稱必須為id_rsa才能生效紧憾,因此無(wú)法實(shí)現(xiàn)多個(gè)秘鑰。)
注意:1-7步生成的id_rsa和id_rsa.pub昌渤,在需要生成多個(gè)key的時(shí)候赴穗,需要將生成的這2個(gè)文件重命名,以免再次生成的時(shí)候被覆蓋膀息。