如何創(chuàng)建公鑰私鑰對(duì)
使用SSH協(xié)議下載,通過公鑰認(rèn)證的方式避免輸入密碼:
客戶在本機(jī)上生成公鑰私鑰對(duì)(使用命令"ssh-keygen",一直回車,不用輸入口令),如下圖所示:
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lordyung/.ssh/id_rsa):
Created directory '/home/lordyung/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/lordyung/.ssh/id_rsa.
Your public key has been saved in /home/lordyung/.ssh/id_rsa.pub.
The key fingerprint is:
c2:a5:f4:f6:82:f8:1d:4e:a7:24:d3:7f:34:c9:e3:d6 lordyung@cm88
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . . |
| o + |
| + S . . |
| . = . * |
| . + * oo + |
| . B * + E |
| . + .o |
+-----------------+
成功后會(huì)在~/.ssh/目錄下生成id_rsa.pub和id_rsa 兩個(gè)文件。
注意事項(xiàng):
1. 公鑰和私鑰文件一定要保存好,不能刪除。最好備份這兩個(gè)文件,誤刪除時(shí)可恢復(fù)。
2. 客戶下載代碼時(shí),如果命令行前面加了sudo,那么生成公鑰的命令 ssh-keygen 前面也要加sudo(也就是要么都加sudo,要么都不加,必須保持一致)。