目標: 在Windows下安裝git,配置公鑰,實現與github賬戶交互(clone項目、push代碼)
第一步:
下載msysgit,下載地址:https://git-for-windows.github.io/。傻瓜式安裝即可。
第二步:
在任意一個文件夾下,右鍵打開快捷菜單,啟動 Git Bash,然后檢查本機是否有ssh key設置。
$ cd ~/.ssh
進入~/.ssh路徑下(ls查看當前路徑文件,rm * 刪除所有文件,也可以不刪,重點是刪除rsa相關的文件)
第三步:
使用Git Bash生成新的ssh key。
$ cd ~
保證當前路徑在”~”下
$ ssh-keygen -t rsa -C "xxxxxx@yy.com"
郵箱為你在github注冊時填寫的郵箱,建議填寫自己真實有效的郵箱地址。
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到GItHub。
登錄GitHub系統;點擊右上角賬號頭像的 “▼” → Settings → SSH kyes → Add SSH key。
復制id_rsa.pub的公鑰內容:
- 進入c:/Users/xxxx_000/.ssh/目錄下,打開id_rsa.pub文件,全選復制公鑰內容。
- Title自定義,將公鑰粘貼到GitHub中Add an SSH key的key輸入框,最后“Add Key”。
第五步:
配置賬戶。
設置用戶名:
$ git config --global user.name “your_username”
設置郵箱地址(建議用注冊giuhub的郵箱):
$ git config --global user.email “your_registered_github_Email”
第六步:
測試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. #出現詞句話,說明設置成功。
第七步:
盡情的玩耍吧~~