標籤:
轉自:http://jingyan.baidu.com/article/a65957f4e91ccf24e77f9b11.html
第一部分介紹:在windows下通過msysGit(Git for windows、Git Bash)配置SSH Keys串連GitHub。
第二部分介紹:在GitHub上建立倉庫,在本地建立項目,然後將本地項目通過SSH提交到GitHub倉庫中。 工具/原料
msysGit配置SSH訪問GitHub
-
1
檢查本機是否有ssh key設定
$ cd ~/.ssh 或cd .ssh
如果沒有則提示: No such file or directory
如果有則進入~/.ssh路徑下(ls查看當前路徑檔案,rm * 刪除所有檔案)
-
2
1、使用Git Bash產生新的ssh key。
$ cd ~ #保證當前路徑在”~”下
$ ssh-keygen -t rsa -C "[email protected]" #建議填寫自己真實有效郵箱地址
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa): #不填直接斷行符號
Enter passphrase (empty for no passphrase): #輸入密碼(可以為空白)
Enter same passphrase again: #再次確認密碼(可以為空白)
Your identification has been saved in /c/Users/xxxx_000/.ssh/id_rsa. #產生的密鑰
Your public key has been saved in /c/Users/xxxx_000/.ssh/id_rsa.pub. #產生的公開金鑰
The key fingerprint is:
e3:51:33:xx:xx:xx:xx:xxx:61:28:83:e2:81 [email protected]
*本機已完成ssh key設定,其存放路徑為:c:/Users/xxxx_000/.ssh/下。
注釋:可產生ssh key自訂名稱的密鑰,預設id_rsa。
$ ssh-keygen -t rsa -C "郵箱地址" -f ~/.ssh/githug_blog_keys #產生ssh key的名稱為githug_blog_keys,慎用容易出現其它異常。
-
3
添加ssh key到GItHub
3.1 登入GitHub系統;點擊右上方帳號頭像的“▼”→Settings→SSH kyes→Add SSH key。
-
4
3.2 複製id_rsa.pub的公開金鑰內容。
1) 進入c:/Users/xxxx_000/.ssh/目錄下,開啟id_rsa.pub檔案,全選複製公開金鑰內容。
2) Title自訂,將公開金鑰粘貼到GitHub中Add an SSH key的key輸入框,最後“Add Key”。
-
5
配置賬戶
$ git config --global user.name “your_username” #設定使用者名稱
$ git config --global user.email “your_registered_github_Email” #設定郵箱地址(建議用註冊giuhub的郵箱)
-
6
測試ssh keys是否設定成功。
$ ssh -T [email protected]
The authenticity of host ‘github.com (192.30.252.129)‘ can‘t be established.
RSA key fingerprint is 16:27:xx:xx:xx:xx:xx:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes #確認你是否繼續聯絡,輸入yes
Warning: Permanently added ‘github.com,192.30.252.129‘ (RSA) to the list of known hosts.
Enter passphrase for key ‘/c/Users/xxxx_000/.ssh/id_rsa‘: #產生ssh kye是密碼為空白則無此項,若設定有密碼則有此項且,輸入產生ssh key時設定的密碼即可。
Hi xxx! You‘ve successfully authenticated, but GitHub does not provide shell access. #出現詞句話,說明設定成功。
END
將本地項目通過SSH push到GitHub
-
在github上建立一個樣本倉庫,如:test ssh key。
-
複製test ssh key的ssh路徑。
-
本地建立項目
1) 建立目錄
$ mkdir test
$ cd test
2) 初始化
$ git init
3) 建立hello.md檔案
$ echo "這是一次測試test ssh key" > hello.md
4) 提交到本地
若出現如上warning提示則重新提交一次即可。
$ git add . #提交目前的目錄下所以檔案
$ git commit -m "add hello.md" #提交記錄說明
5) 提交到github
$ git remote add origin ‘粘貼複製test ssh key的ssh路徑’ #
$ git push -u origin master
Enter passphrase for key ‘/c/Users/hgpin_000/.ssh/id_rsa‘: #ssh key設定密碼故此需要輸入密碼
-
重新整理test ssh key倉庫,查看hello.md。(完)
步驟閱讀
END
注意事項
window下配置SSH串連GitHub、GitHub配置ssh key(轉)