一、生成SSH密鑰
1、打開Git Bash
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
按照提示輸入保存路徑和passphrase
2、在Github上添加SSH公鑰
將id_rsa.pub的內容複製到Github賬號的SSH Keys中
二、測試SSH連接
1、測試SSH agent是否正在運行
$ eval "$(ssh-agent -s)"
Agent pid 59566
2、將SSH私鑰添加到SSH agent
$ ssh-add ~/.ssh/id_rsa
3、測試SSH連接是否成功
$ ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
三、配置SSH別名
1、打開~/.ssh/config文件
$ nano ~/.ssh/config
2、添加以下內容
#Default Github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
#Personal Github
Host github-personal
HostName github.com
IdentityFile ~/.ssh/id_rsa_personal
3、使用SSH別名進行克隆或推送
$ git clone git@github-personal:account/repo.git
$ git push -u origin master
四、配置Git全局SSH
1、設置Git全局用戶信息
$ git config --global user.name "username"
$ git config --global user.email "email@example.com"
2、將SSH公鑰添加到Github賬號
在Github賬號的SSH Keys中添加id_rsa.pub的內容
3、測試SSH連接是否成功
$ ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
五、總結
以上就是Github配置SSH的詳細步驟,通過配置SSH可以避免每次提交時都需要輸入Github賬號的密碼,提高工作效率。
原創文章,作者:VESMO,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/369436.html