標籤:style blog color os 使用 io 檔案 for ar
使用ssh key驗證github的好處就是不用每次提交代碼的時候都要輸入使用者名稱和密碼,因為著在一定程度上對效率有很大的影響,雖然這麼做可以防止代碼提交的次數過多,但這也看個人的習慣吧。
今天嘗試了一下配置ssh key
OS:mac os
開啟控制台,建一個目錄,比如~/.ssh(其實叫什麼都無所謂,網上搜的基本上都這麼配置)
在該目錄下輸入命令:
ssh-keygen -t rsa -C "[email protected]"
注意:雙引號換成自己的郵箱,如果遇到許可權問題,只需在前面加上sudo
Generating public/private rsa key pair.Enter file in which to save the key (/var/root/.ssh/id_rsa): ./id_rsa#這裡填的是儲存檔案的路徑Enter passphrase (empty for no passphrase):#直接enter跳過 Enter same passphrase again: #同上Your identification has been saved in ./id_rsa.Your public key has been saved in ./id_rsa.pub.The key fingerprint is:25:68:54:4a:f1:03:ab:78:15:3f:f7:9d:f0:bf:08:ee [email protected]The key‘s randomart image is:+--[ RSA 2048]----+| *o. || o O || * * o . || . + * . + . || . o S . + || . . || . .|| . . . .|| .E . . |+-----------------+
這個時候,在.ssh目錄下有兩個檔案
id_rsa id_rsa.pub
其中id_rsa是私密金鑰 id_rsa.pub是公開金鑰
然後,執行下面的命令,將產生的key添加
ssh-add id_rsa
然後將id_rsa.pub裡面的內容複寫下來,在github上的settings裡面找到add keys,將其粘貼到key即可,title隨便填
這個時候可以在控制台上測試一下
$ ssh -T [email protected]The authenticity of host ‘github.com (192.30.252.128)‘ 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)? yesFailed to add the host to the list of known hosts (/Users/Bsn/.ssh/known_hosts).Hi bsnwong! You‘ve successfully authenticated, but GitHub does not provide shell access.
其他不用管,只要看到最後一行,說明驗證成功了
後話:剛開始忘記執行ssh-add id_rsa 命令,一直驗證不成功,困在這裡好久
使用 ssh key 驗證 github