git初始化配置

如何生成SSH key

SSH key提供了一種與GitHub通訊的方式,經過這種方式,可以在不輸入密碼的狀況下,將GitHub做爲本身的remote端服務器,進行版本控制前端

步驟

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

1. 檢查SSH keys是否存在

輸入下面的命令,若是有文件id_rsa.pubid_dsa.pub,則直接進入步驟3將SSH key添加到GitHub中,不然進入第二步生成SSH keygit

ls -al ~/.ssh
複製代碼

以下圖就表示存在,能夠直接跳入第三步:github

2. 生成新的ssh key

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

默認會在相應路徑下(/your_home_path)生成id_rsaid_rsa.pub兩個文件,以下面代碼所示web

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):
複製代碼
  1. 第二步:輸入passphrase(本步驟能夠跳過)

設置passphrase後,進行版本控制時,每次與GitHub通訊都會要求輸入passphrase,以免某些「失誤」segmentfault

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
複製代碼

sample result:bash

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
複製代碼
  1. 第三步:將新生成的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中

用本身喜歡的文本編輯器打開id_rsa.pub文件,裏面的信息即爲SSH key,將這些信息複製到GitHub的Add SSH key頁面便可服務器

不一樣的操做系統,均有一些命令,直接將SSH key從文件拷貝到粘貼板中,以下:ssh

  • 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
複製代碼

複製上面的key後粘貼到github new key便可,以下圖:編輯器

其餘

聯繫

若是你們有興趣,歡迎關注公衆號:_facebook(web技術進階),查看更多優質文章,歡迎你們加入個人前端交流羣:866068198 ,一塊兒交流學習前端技術。博主目前一直在自學Node中,技術有限,若是能夠,會盡力給你們提供一些幫助,或是一些學習方法.ide

  • 公衆號
  • 羣二維碼

福利

有須要刷鑽,刷會員,刷騰訊視頻會員,漲粉絲等等相關意向的小夥伴們,能夠訪問做者推薦的超值代刷網站:qq.usword.cn, 也能夠掃描下方二維碼

最後

If you have some questions after you see this article, you can contact me or you can find some info by clicking these links.

相關文章
相關標籤/搜索