ubuntu 16.04如何生成ssh key以及如何查看ssh key

檢查本地是否有SSH Key存在javascript

在終端輸入css

ls -al ~/.ssh

若是輸出的是:java

No such file or directory

那就沒有ssh keydom

若是有就會出現這樣:ssh

生成新的SSH key

首先在終端輸入ide

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

your_email@example.com 爲你在 GitHub或者GitLab 註冊時的郵箱
回車後終端會顯示:spa

  1.  
    Created directory '/Users/xxx/.ssh'.
  2.  
    Enter passphrase ( empty for no passphrase):

提示你保存 .ssh/id_rsa 的路徑是/Users/xxx/.ssh/id_rsa,直接按回車。
這裏有一點,若是已經存在SSH key你想要使用以上操做從新生成的話會提示一你不是要從新生成,直接輸入y並按回車。
而後終端會提示:3d

  1.  
    Created directory '/Users/xxx/.ssh'.
  2.  
    Enter passphrase ( empty for no passphrase):

提示設置 passphrase,每次與 Git 通訊都會要求輸入 passphrase,以免某些錯誤的操做所致使的問題,建議設置一下。

成功後終端會提示:code

  1.  
    Your identification has been saved in /Users/xxx/.ssh/id_rsa.
  2.  
     
  3.  
    Your public key has been saved in /Users/xxx/.ssh/id_rsa.pub.
  4.  
     
  5.  
    The key fingerprint is:
  6.  
     
  7.  
    16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48 your_email@example.com
  8.  
     
  9.  
    The key's randomart image is:
  10.  
     
  11.  
    心形圖形

而後在終端輸入:blog

ssh-add ~/.ssh/id_rsa

此時會要求輸入上面步驟裏所填的 passphrase
成功後,終端顯示:

Identity added: /Users/xxx/.ssh/id_rsa (/Users/xxx/.ssh/id_rsa)

最後,在 /Users/xxx/.ssh/ 生成兩個文件,id_rsa 和 id_rsa.pub
在終端輸入:

cat /Users/xxx/.ssh/id_rsa.pub

終端就會顯示你的SSH key了,直接複製就能夠了。

就這些啦~~O(∩_∩)O哈哈~

相關文章
相關標籤/搜索