1.爲何要添加公鑰git
git使用https協議,每次pull, push都要輸入密碼,至關的煩。
使用git協議,而後使用ssh密鑰。這樣能夠省去每次都輸密碼。github
2.步驟bash
基本步驟以下:ssh
1. 設置Git的user name和emailcode
git config --global user.name "guozhenhua" //xxxx爲git用戶名 git config --global user.email "84424146@qq.com" //xxxx@xxxx.com爲註冊git的郵箱
2. 查看是否已經有了ssh密鑰:cd ~/.ssh => open ./ it
//成功後個人有id_rsa、id_rsa.pub、known_hosts這三個文件class
若是沒有密鑰則不會有此文件夾,有則備份刪除email
3. 清除全部的公鑰:ssh-add -Drsa
刪除git中的公鑰:rm -r ~/.ssh密碼
4.你能夠按以下命令來生成 sshkey:
ssh-keygen -t rsa -C "84424146@qq.com" # Generating public/private rsa key pair... # 三次回車便可生成 ssh key
查看你的 public key
cat ~/.ssh/id_rsa.pub # ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....
複製公鑰,將公鑰加入 github等