參考資料:win set up git (官方網站)
首先,下載Git for Windows (我是下載Git-1.7.3.1-preview20101002.exe)
使用預設選項一路按Next安裝下去
完成後就能執行Git Bash囉!
點開Git Bash後
[指令可複製黑底白字的部分其他顏色的字則是系統跑出來的]
Set Up SSH Keys
Step 1. Check for SSH Keys
(如果已經有SSH Key,可以跳到Step4)
輸入
$ cd ~/.ssh
如果出現 “No such file or directory“ ,則可以跳到Step 3
Step 2. 備份&移除已存在的SSH Keys
$ ls
config id_rsa id_rsa.pub known_hosts
如果上面這行沒出現 “id_rsa id_rsa“ ,則一樣跳到Step 3
$ mkdir key_backup
$ cp id_rsa* key_backup
$ rm id_rsa*
Step 3. 重新產生新的SSH Keys
$ ssh-keygen -t rsa -C "xxx@xxx.com" 這邊請自行輸入你的mail
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<press enter>
直接按enter
Enter passphrase (empty for no passphrase):<enter a passphrase>
Enter same passphrase again:<enter passphrase again>
繼續enter
然後你應該會看到以下畫面
Your identification has been saved in /Users/your_user_directory/.ssh/id_rsa.
Your public key has been saved in /Users/your_user_directory/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db xxx@xxx.com
Step 4. 重新產生新的SSH Keys
連到GitHub官網,開啟以下路徑Account Settings > SSH Public Keys >Add another public key
點下去之後會出現上面的表格,Title可以輸入你這組Key的位置方便管理(ex. my sweet home 之類的XD)
Key則要打開C:\Documents and Settings\username\.ssh下的id_rsa檔(可以用筆記本、Notepad之類的純文字編輯器打開)
或者是直接在Git Bash內輸入 (推薦使用)
$ cat ~/.ssh/id_rsa.pub
來顯示產生的key,複製紅框裡面的資訊再貼上
!!!Point!!!不論是用哪種方法打開,都要記得把換行的部分消掉再貼,不然一定會失敗喔!
新增完成後就OK囉!!!
Step 5. 測試一下
打開Git Bash輸入
$ 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 username! You've successfully authenticated, but GitHub does not provide shell access.
看到以上資訊就代表你成功囉!!!!
但如果出現以下資訊
Agent admitted failure to sign using the key
要再執行
$ ssh-add ~/.ssh/id_rsa
OK!!!打完收工!!!