首先,咱們須要看看是否看看本機是否存在SSH keys,打開Git Bash,並運行: git
1
|
$
cd
~
/
.
ssh
#
|
檢查你本機用戶home目錄下是否存在.ssh目錄 github
若是,不存在此目錄,則進行第二步操做,不然,你本機已經存在ssh公鑰和私鑰,能夠略過第二步,直接進入第三步操做。 shell
輸入以下命令: 安全
1
2
3
4
|
$
ssh
-
keygen
-
t
rsa
-
C
"your_email@example.com"
#這將按照你提供的郵箱地址,建立一對密鑰
Generating
public
/
private
rsa
key
pair
.
Enter
file
in
which
to
save
the
key
(
/
c
/
Users
/
you
/
.
ssh
/
id_rsa
)
:
[
Press
enter
]
|
直接回車,則將密鑰按默認文件進行存儲。此時也能夠輸入特定的文件名,好比/c/Users/you/.ssh/github_rsa ssh
接着,根據提示,你須要輸入密碼和確認密碼(說到這裏,若是你很放心,其實能夠不用密碼,就是到輸密碼的地方,都直接回車,因此每次push就只管回車就好了。所謂的最安全的密碼,就是沒有密碼 – – 哈哈)。相關提示以下: ide
1
2
|
Enter
passphrase
(
empty
for
no
passphrase
)
:
[
Type
a
passphrase
]
Enter
same
passphrase
again
:
[
Type
passphrase
again
]
|
輸入完成以後,屏幕會顯示以下信息: 測試
1
2
3
4
|
Your
identification
has
been
saved
in
/
c
/
Users
/
you
/
.
ssh
/
id_rsa
.
Your
public
key
has
been
saved
in
/
c
/
Users
/
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
your_email
@
example
.
com
|
運行以下命令,將公鑰的內容複製到系統粘貼板(clipboard)中。 spa
1
|
clip
<
~
/
.
ssh
/
id_rsa
.
pub
|
接着: ip
1. 登錄GitHub,進入你的Account Settings. ci
2. 在左邊菜單,點擊」SSH Keys」.
3. 點擊」Add SSH key」按鈕.
4. 粘貼你的密鑰到key輸入框中.
5. 點擊」Add Key」按鈕。
6. 再彈出窗口,輸入你的GitHub密碼,點擊確認按鈕。
7. 到此,大功告成了!
爲了確認咱們能夠經過SSH鏈接GitHub,咱們輸入下面命令。輸入後,會要求咱們提供驗證密碼,輸入以前建立的密碼就ok了。
1
|
$
ssh
-
T
git
@
github
.
com
|
你可能會看到告警信息,以下:
1
2
3
|
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.