如何创建公钥私钥对
使用SSH协议下载,通过公钥认证的方式避免输入密码:
客户在本机上生成公钥私钥对(使用命令"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 |
+-----------------+
成功后会在~/.ssh/目录下生成id_rsa.pub和id_rsa 两个文件。
注意事项:
1. 公钥和私钥文件一定要保存好,不能删除。最好备份这两个文件,误删除时可恢复。
2. 客户下载代码时,如果命令行前面加了sudo,那么生成公钥的命令 ssh-keygen 前面也要加sudo(也就是要么都加sudo,要么都不加,必须保持一致)。