1. 程式人生 > >Windows客戶端配置GitHub的SSH公鑰

Windows客戶端配置GitHub的SSH公鑰

... add 繼續 ide file targe http win cati

檢查SSH keys的設置

$ cd ~/.ssh/

如果顯示”No such file or directory”,跳到第三步,否則繼續。

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

如果已經存在key文件,需要備份該數據並刪除之

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

生成新的SSH key

輸入下面的代碼,可以生成新的key文件,只需要使用默認的設置即可,當需要輸入文件名的時候,回車即可

$ 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 keys 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任意選擇。

測試一下

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

$ ssh -T [email protected]
The authenticity of host github.com (192.30.255.112) cant 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)? y
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! Youve 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的說明)

Windows客戶端配置GitHub的SSH公鑰