一.配置郵箱和用戶名
git config --global user.name "自定義用戶名"
git config --global user.email "郵箱"? ? ?(郵箱和網(wǎng)站的郵箱需要保持一致)
用戶名郵箱配置后通過下面指令查看是否成功
git config user.name
git config user.email
二.生成SSH Key
進(jìn)入 ~/.ssh目錄淹朋,命令行生成公鑰和私鑰
ssh-keygen -t rsa -C "郵箱"
輸入文件名和私鑰密碼
結(jié)束后胖替,用下面命名查看下
cat ~/.ssh/rsa_key.pub
三.GitHub SSH Key配置
將上面cat出來的字符串復(fù)制到我們的github網(wǎng)站上進(jìn)行配置。
四.驗(yàn)證配置正確性
執(zhí)行? ?git clone “代碼庫”
發(fā)現(xiàn)報(bào)錯(cuò):Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
原因:說明私鑰沒有被加載
解決辦法:ssh-add? ~/.ssh/私鑰
運(yùn)行ssh-add,如果提示““Could not open a connection to your authentication agent.”
說明ssh-agent沒有運(yùn)行歼捐,需要先運(yùn)行ssh-agent舞骆,再ssh-add
在macOS/Linux
$ eval `ssh-agent`
ssh-add ~/.ssh/other_id_rsa
在Windows中的git-bash中
$ eval $(ssh-agent)
ssh-add ~/.ssh/other_id_rsa
運(yùn)行后就可以拉取代碼了