1. 程式人生 > >Git學習-配置SSH訪問GitHub

Git學習-配置SSH訪問GitHub

檢查本機是否有ssh key設定

cd ~/.ssh

如果提示:No such file or directory

則使用Git Bash生成新的ssh key。

$ cd ~  #保證當前路徑在”~”下

$ ssh-keygen -t rsa -C "[email protected]"  #填寫自己真實有效的郵箱地址

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 

[email protected]

*本機已完成ssh key設定,其存放路徑為:c:/Users/xxxx_000/.ssh/下。

註釋:可生成ssh key自定義名稱的金鑰,預設id_rsa。

複製id_rsa.pub(公鑰)內容

登陸GitHub系統

點選右上角賬號頭像的→Settings→SSH and GPG keys→New SSH key

Title自定義,自己可以識別就行,將複製到公鑰貼上到key的輸入框中

然後Add SSH key

配置賬戶

$ git config --global user.name “your_username”  #設定使用者名稱

$ git config --global user.email “your_registered_github_Email”  #設定郵箱地址(建議用註冊giuhub的郵箱)

測試ssh keys是否設定成功。

$ ssh -T [email protected]

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. #出現詞句話,說明設定成功。