創建SSH密鑰
阿新 • • 發佈:2017-10-09
method keys creates provided dmi generate 郵箱 content cit
Step1: 檢查SSH密鑰
首先,打開終端,輸入以下指令,查看是否已經生成SSH密鑰。
cd ~/.ssh
ls
# Lists the files in your .ssh directory
在輸入ls後,看看是否有文件 id_rsa.pub 或者 id_dsa.pub,或者兩者皆有。如果已經存在這兩個文件,則不需進行Step 2,之前如果輸入了密碼,可以直接跳過Step3。
Step2: 生成新的SSH密鑰
輸入下面的第一條指令,指令中輸入一個郵箱,會出現要你自己定義一個文件來保存Key,直接Enter通過。
ssh-keygen -t rsa -C "[email protected]"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):
輸入密碼(不能少於4個,否則重輸入)。
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
終端給出的信息如下,告訴Key的保存位置,後面需要用到。
# Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Step3: 添加SSH Key到GitHub
運行下面這些指令:(打了#號的不用,)。
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
進入網站GitHub,對以下進行設置:
1. 點擊賬戶設置(很明顯的,就在右上角);
2. 點擊 "SSHKeys" 在左邊;
3. 工作區出現
點擊Add SSH key,出現下面。
4. 點擊 "Add key"
5. 輸入密碼進行確認,這個密碼就是在Step 3中輸入的密碼,這個彈出窗口會在輸入
xclip -sel clip < ~/.ssh/id_rsa.pub
指令是出現。
Step4: 測試是否成功
ssh -T [email protected]
# Attempts to ssh to github
輸入上面的指令,而且指令中的[email protected]是不可以隨意輸的,一般就是這個,其實也就是這個。
可能出現的錯誤信息:
...
Agent admitted failure to sign using the key.
debug1: No more authentication methods to try.
Permission denied (publickey).
警告:
# The authenticity of host ‘github.com (207.97.227.239)‘ 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)?
莫擔心,沒事的,輸入yes,直接秒殺。
# Hi username! You‘ve successfully authenticated, but GitHub does not
# provide shell access.
成功的是:
If that username is correct, you‘ve successfully set up your SSH key. Don‘t worry about the shell access thing, you don‘t want that anyway.
創建SSH密鑰