使用SSH協議,能夠鏈接到遠程服務器和服務並進行身份驗證。 使用SSH密鑰,能夠鏈接到GitHub,而無需在每次訪問時都提供用戶名或密碼。git
打開 Git Bash 並輸入如下命令(用你的GitHub電子郵件地址替換命令中的電子郵件地址)github
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
當看到如下命令提示時,按回車,就會把文件存在默認的路徑下(能夠改路徑,改路徑後,在後邊的操做須要額外的操做,這裏我不改路徑)服務器
> Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):
當看到如下命令提示時,輸入自定義密碼(不是GitHub密碼),這個密碼在鏈接GitHub時會用到,好比pull、push的時候ssh
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
確保生成成功fetch
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
將新的SSH密鑰添加到GitHub賬戶後,就能夠從新配置任何本地倉庫以使用SSH。網站
複製SSH Keyurl
clip < ~/.ssh/id_rsa.pub
在GitHub網站頁面,點擊右上角的我的頭像,點擊Settingscode
點擊左側欄目中的「SSH and GPG keys」blog
點擊右上角的「New SSH key」ip
在打開的頁面中的Title中填入這個key的描述,如Company Computer;在Key中粘貼複製的SSH Key;而後點擊Add SSH Key按鈕
在彈出的頁面中輸入Github密碼
完成添加
git remote -v > origin https://github.com/USERNAME/REPOSITORY.git (fetch) > origin https://github.com/USERNAME/REPOSITORY.git (push)
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
git remote -v # Verify new remote URL > origin git@github.com:USERNAME/REPOSITORY.git (fetch) > origin git@github.com:USERNAME/REPOSITORY.git (push)
到此,切換完成。後續的pull、push等操做就會使用SSH了
從新生成一個SSH Key,添加到github便可