window下配置SSH连接GitHub、GitHub配置ssh key
此經驗分兩部分:
第一部分介紹:在windows下通過msysGit(Git for windows、Git Bash)配置SSH Keys連接GitHub。
第二部分介紹:在GitHub上創建倉庫,在本地創建項目,然后將本地項目通過SSH提交到GitHub倉庫中。
工具/原料
- GitHub
- msysGit(git for windows、Git Bash)
msysGit配置SSH訪問GitHub
檢查本機是否有ssh?key設置
$?cd?~/.ssh?或cd?.ssh
如果沒有則提示:?No?such?file?or?directory
如果有則進入~/.ssh路徑下(ls查看當前路徑文件,rm?*?刪除所有文件)
1、使用Git?Bash生成新的ssh?key。
$?cd?~??#保證當前路徑在”~”下
$?ssh-keygen?-t?rsa?-C?"xxxxxx@yy.com"??#建議填寫自己真實有效的郵箱地址
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?xxxxxx@yy.com
?
*本機已完成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,慎用容易出現其它異常。
添加ssh?key到GItHub
3.1 登錄GitHub系統;點擊右上角賬號頭像的“▼”→Settings→SSH?kyes→Add?SSH?key。
3.2 復制id_rsa.pub的公鑰內容。?
1) 進入c:/Users/xxxx_000/.ssh/目錄下,打開id_rsa.pub文件,全選復制公鑰內容。
2) Title自定義,將公鑰粘貼到GitHub中Add?an?SSH?key的key輸入框,最后“Add?Key”。
配置賬戶
$?git?config?--global?user.name?“your_username”??#設置用戶名
$?git?config?--global?user.email?“your_registered_github_Email”??#設置郵箱地址(建議用注冊giuhub的郵箱)
測試ssh?keys是否設置成功。
$?ssh?-T?git@github.com
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注意事項
- 經驗適用于win7、win8.1、win10。
轉載于:https://www.cnblogs.com/hukai46/p/5489631.html
總結
以上是生活随笔為你收集整理的window下配置SSH连接GitHub、GitHub配置ssh key的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对象构造函数的原型图
- 下一篇: 写一些脚本的心得总结系列第3篇-----