如何生成SSH key

如何生成SSH key

本文載于Gevin的博客
原文地址:http://blog.igevin.info/posts/generate-ssh-key-for-git/

SSH key提供了一種與GitHub通信的方式,通過(guò)這種方式,能夠在不輸入密碼的情況下,將GitHub作為自己的remote端服務(wù)器,進(jìn)行版本控制

步驟

  • 檢查SSH keys是否存在
  • 生成新的ssh key
  • 將ssh key添加到GitHub中
如何生成SSH KEY
如何生成SSH KEY

1. 檢查SSH keys是否存在

輸入下面的命令,如果有文件id_rsa.pubid_dsa.pub,則直接進(jìn)入步驟3將SSH key添加到GitHub中,否則進(jìn)入第二步生成SSH key

ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2. 生成新的ssh key

第一步:生成public/private rsa key pair
在命令行中輸入ssh-keygen -t rsa -C "your_email@example.com"

默認(rèn)會(huì)在相應(yīng)路徑下(/your_home_path)生成id_rsaid_rsa.pub兩個(gè)文件,如下面代碼所示

ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):

第二步:輸入passphrase(本步驟可以跳過(guò))

設(shè)置passphrase后,進(jìn)行版本控制時(shí),每次與GitHub通信都會(huì)要求輸入passphrase,以避免某些“失誤”

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

sample result:

Your identification has been saved in /your_home_path/.ssh/id_rsa.
Your public key has been saved in /your_home_path/.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

第三步:將新生成的key添加到ssh-agent中:

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa

3. 將ssh key添加到GitHub中

用自己喜歡的文本編輯器打開(kāi)id_rsa.pub文件,里面的信息即為SSH key,將這些信息復(fù)制到GitHub的Add SSH key頁(yè)面即可

不同的操作系統(tǒng),均有一些命令,直接將SSH key從文件拷貝到粘貼板中,如下:

mac

pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

windows

clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

linux

sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

本文首載于Gevin's blog

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 如何生成SSH key 本文載于Gevin的博客 原文地址:http://blog.igevin.info/pos...
    蕭玄辭閱讀 791評(píng)論 0 0
  • SSH key提供了一種與GitHub通信的方式,通過(guò)這種方式,能夠在不輸入密碼的情況下,將GitHub作為自己的...
    pengshuangta閱讀 3,218評(píng)論 1 2
  • 轉(zhuǎn)自別處: SSH key提供了一種與GitHub通信的方式,通過(guò)這種方式,能夠在不輸入密碼的情況下,將GitHu...
    Ten_Minutes閱讀 757評(píng)論 0 3
  • 一、檢查SSH key是否存在 在終端輸入: ls -al ~/.ssh 如果沒(méi)有,終端顯示如下: No such...
    JackieWillen閱讀 1,620評(píng)論 0 0
  • 操作環(huán)境為 Mac os,如果你是 Windows 請(qǐng)出門(mén)左轉(zhuǎn)。 一、檢查 SSH key 是否存在 在終端輸入:...
    bincn閱讀 8,628評(píng)論 1 16

友情鏈接更多精彩內(nèi)容