https://segmentfault.com/a/1190000002645623
1、設(shè)置Git的user name和email:(如果是第一次的話)
$ git config --global user.name"humingx"$ git config --global user.email"humingx@yeah.net"
2休讳、生成密鑰
$ssh-keygen -t rsa -C"humingx@yeah.net"
連續(xù)3個回車凑保。如果不需要密碼的話。
最后得到了兩個文件:id_rsa和id_rsa.pub。
如果不是第一次择膝,就選擇overwrite.
3奢米、添加密鑰到ssh-agent
確保 ssh-agent 是可用的。ssh-agent是一種控制用來保存公鑰身份驗證所使用的私鑰的程序讶迁,其實ssh-agent就是一個密鑰管理器连茧,運(yùn)行ssh-agent以后,使用ssh-add將私鑰交給ssh-agent保管巍糯,其他程序需要身份驗證的時候可以將驗證申請交給ssh-agent來完成整個認(rèn)證過程啸驯。
# start the ssh-agent in the backgroundeval"$(ssh-agent -s)"Agent pid 59566
添加生成的 SSH key 到 ssh-agent。
$ ssh-add~/.ssh/id_rsa
4祟峦、登陸Github, 添加 ssh 罚斗。
把id_rsa.pub文件里的內(nèi)容復(fù)制到這里
5、測試:
$ssh -T git@github.com
你將會看到:
The authenticityofhost'github.com (207.97.227.239)' can't be established.RSAkeyfingerprintis16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.Are you sure you wanttocontinueconnecting (yes/no)?
選擇yes
Hi humingx! You'vesuccessfully authenticated, but GitHub doesnotprovide shellaccess.
如果看到Hi后面是你的用戶名宅楞,就說明成功了针姿。
6、修改.git文件夾下config中的url咱筛。
修改前
[remote"origin"]? ? url =https://github.com/humingx/humingx.github.io.gitfetch = +refs/heads/*:refs/remotes/origin/*
修改后
[remote"origin"]? ? url = git@github.com:humingx/humingx.github.io.git? ? fetch = +refs/heads/*:refs/remotes/origin/*
7搓幌、發(fā)布