github使用SSH Access

如果你要從local端git push上github,若你使用的是https Access,它會要求你輸入密碼,但SSH就不用,也比較安全跟方便,以下是步驟,以下做個筆記。

Step1:check自己跟目錄有沒有.ssh,有的話跳到Step3,沒有跳到Step2

cd ~/.ssh

Step2:產生妳的ssh key

ssh-keygen -t rsa -C "your_email@example.com"

Step3:接著它會要求妳輸入passphrase,按enter即可

Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

接著你會看到以下訊息:

Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

Step4:將SSH KEY複製到github

先複製剛剛的SSH key,它在.ssh下的id_rsa.pub

clip < ~/.ssh/id_rsa.pub

接著到Github的 Account Settings,點選SSH KEY,再點選Add SSH Key,將剛剛複製起來的貼到text欄位即可。

Step5:測試一下

輸入以下指令

ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.

如果出現以上訊息,表示已經完成了。接下來都可以用SSH Access,git push也不需要密碼了,git clone的時候記得選SSH 就可以囉:)。