git config --global user.name "songkunpeng"
git config --global user.email "your.email@example.com"
ssh-add -K ~/.ssh/id_rsa
-
設置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" (和git的email 保持一致)
3、添加密鑰到ssh-agent
確保 ssh-agent 是可用的。ssh-agent是一種控制用來保存公鑰身份驗證所使用的私鑰的程序,其實ssh-agent就是一個密鑰管理器,運行ssh-agent以后,使用ssh-add將私鑰交給ssh-agent保管,其他程序需要身份驗證的時候可以將驗證申請交給ssh-agent來完成整個認證過程。
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
添加生成的 SSH key 到 ssh-agent。
$ ssh-add ~/.ssh/id_rsa
4、登陸Github, 添加 ssh 。
把id_rsa.pub
文件里的內容復制到這里
5、測試:
$ ssh -T git@github.com
你將會看到:
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
選擇 yes
Hi humingx! You've successfully authenticated, but GitHub does not provide shell access.
如果看到Hi
后面是你的用戶名,就說明成功了。
6、修改.git
文件夾下config
中的url
。
修改前
[remote "origin"]
url = https://github.com/humingx/humingx.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
修改后
[remote "origin"]
url = git@github.com:humingx/humingx.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
7、發布
[圖片描述](https://segmentfault.com/img/bVlgoT)
``