使用 ssh key 驗證 github

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.