Windows客戶端配置GitHub的SSH公鑰

檢查SSH keys的設置

$ cd ~/.ssh/

若是顯示」No such file or directory」,跳到第三步,不然繼續。git

備份和移除原來的SSH key設置

若是已經存在key文件,須要備份該數據並刪除之github

$ ls
id_rsa  id_rsa.pub  known_hosts
$ mkdir key_backup
$ cp id_rsa* key_backup/
$ rm id_rsa*

生成新的SSH key

輸入下面的代碼,能夠生成新的key文件,只須要使用默認的設置便可,當須要輸入文件名的時候,回車便可shell

$ ssh-keygen -t rsa -C "你的郵箱@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/WX/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/WX/.ssh/id_rsa.
Your public key has been saved in /c/Users/WX/.ssh/id_rsa.pub.
The key fingerprint is:
1d:cc:7e:b3:7e:92:f7:ab:c6:75:56:73:62:30:bc:8c 你的郵箱@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
|           .     |
|         o  +    |
|          +o +   |
|         oE.o o.o|
|        S o o. .+|
|           . o .o|
|            o....|
|           .ooo  |
|            o=.oo|
+-----------------+
Enter passphrase (empty for no passphrase):這裏能夠輸入密碼,在登陸時驗證

添加SSH key到GitHub

用文本編輯工具打開id_rsa.pub文件,若是看不到這個文件,你須要設置顯示隱藏文件。準確的複製這個文件的內容,才能保證設置的成功。
在GitHub的主頁上點擊設置按鈕,選擇SSH Keys項,把複製的內容粘貼進去,而後點擊Add Key按鈕便可,Title任意選擇。dom

測試一下

輸入下面命令,測試是否設置成功(第一次登陸)ssh

$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.255.112)' 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
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of know
n hosts.
Enter passphrase for key '/c/Users/dyf/.ssh/id_rsa':(若是上一步設置密碼 這裏須要輸入)
Hi dyf007! You've successfully authenticated, but GitHub does not provide shell
access.

參考:http://codepub.cn/2015/06/02/Windows-client-configuration-of-SSH-public-key-on-GitHub/    (這裏有設置多個sshKey的說明)ide

相關文章
相關標籤/搜索