[root@localhost ~]# cd /etc/pki/CA [root@localhost CA]# touch index.txt #生成证书索引数据库文件 [root@localhost CA]# echo 0F > serial #指定第一个颁发证书的序列号 [root@localhost CA]# (umask 066;openssl genrsa -out private/cakey.pem 4096 ) #生成私钥 Generating RSA private key, 4096 bit long modulus .......++ .........................................++ e is 65537 (0x10001) [root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 #给自己颁发证书 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:beijin Locality Name (eg, city) [Default City]:beijin Organization Name (eg, company) [Default Company Ltd]:ailibaba Organizational Unit Name (eg, section) []:taobao Common Name (eg, your name or your server's hostname) []:www.taobao.com Email Address [] [root@localhost CA]# tree . ├── cacert.pem ├── certs ├── crl ├── index.txt ├── newcerts ├── private │ └── cakey.pem └── serial 4 directories, 4 files [root@localhost CA]# openssl x509 -in cacert.pem -noout -text # 以易读方式打开证书 Certificate: Data: Version: 3 (0x2) Serial Number: f6:4f:6a:1f:a6:de:88:9a Signature Algorithm: sha256WithRSAEncryption Issuer: C=CN, ST=beijin, L=beijin, O=ailibaba, OU=taobao, CN=www.taobao.com Validity Not Before: Apr 18 07:51:512019 GMT Not After : Apr 15 07:51:512029 GMT Subject: C=CN, ST=beijin, L=beijin, O=ailibaba, OU=taobao, CN=www.taobao.com Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (4096 bit) Modulus: 00:ed:09:66:55:c8:65:18:a7:aa:7d:0b:fe:d3:91: b3:f2:a2:a2:4a:ca:02:34:70:37:5d:80:8c:21:79: e9:58:78:73:98:8c:c4:e5:43:ee:44:ca:60:72:50: 05:43:d4:cc:4a:bc:b7:4a:33:53:13:b0:df:b0:5d: ac:9d:a3:af:70:37:ca:09:4e:ce:69:77:2a:1a:ee: db:40:0c:d5:49:be:c0:a0:f6:a4:8d:33:20:57:54: 30:ce:74:fe:cd:30:3f:8d:9f:bc:f9:0e:db:1f:7c: 93:ab:ad:41:78:53:b5:f9:a2:8c:d4:48:80:82:e0: aa:13:45:73:22:f0:41:16:a1:1f:59:bb:c1:7e:58: 16:3c:24:ac:1b:53:19:0b:81:87:f7:9b:b6:86:4e: 82:c4:7a:29:d1:39:54:d9:36:b0:7b:95:79:fc:13: 29:48:d2:cc:b0:ae:34:f0:22:8f:df:b3:76:8a:84: 3a:ce:36:97:85:3d:10:50:a7:12:24:17:1d:9d:bf: f8:e9:7c:7b:b4:67:c9:1f:41:ee:19:45:9b:39:70: d7:9e:7f:97:44:1e:f5:ee:cb:70:e6:6a:f7:8f:a6: 44:da:00:18:c3:de:4b:66:8f:d7:45:a7:09:43:f1: be:0c:68:1a:18:ae:05:61:1f:2f:01:c7:8d:74:3f: 7f:b5:5b:65:dd:6e:d9:47:0f:38:b3:ff:7c:92:95: 48:de:d5:44:17:07:da:5e:bd:00:e8:03:bd:ee:47: 3f:7a:14:a6:63:1c:29:d8:16:ce:26:1a:2a:ee:bd: 57:43:d0:4d:08:52:96:e4:68:0a:b5:19:c9:ea:4d: 42:53:ec:3a:45:a6:ca:68:b9:e8:2e:38:f0:4c:51: 4b:e9:20:5c:f4:b4:7b:20:6a:dd:21:31:49:d6:b1: 39:0f:dc:22:52:2c:cb:94:21:af:e6:82:09:a8:08: ef:f1:21:61:da:fb:ba:ce:8f:70:4d:e0:d9:b0:d1: 6e:42:37:33:f0:8d:57:14:56:6a:5e:2c:60:8e:3f: 05:06:35:53:e0:0b:81:9a:11:38:b1:95:c6:f6:1d: f6:85:61:99:b6:bc:d0:2e:ab:d9:5e:6a:53:4e:95: 5e:a5:a5:4d:6a:45:3b:dd:d5:c4:1b:d1:95:f0:24: a0:7c:19:42:8b:2e:cd:df:a7:2d:e3:d6:a4:f7:22: a4:52:bd:2c:0f:77:fc:b3:27:89:55:31:0a:8f:2a: 3a:ec:07:45:29:96:09:f5:e6:95:87:e2:21:c8:a1: be:6b:f8:95:9a:9c:08:52:48:19:c0:0c:a4:d8:37: 19:42:98:21:40:45:3c:6a:ff:e7:33:8d:1f:2f:ef: 73:c5:5f Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: D5:5D:21:99:D3:9A:BA:90:16:F4:BF:2D:78:C7:27:DF:F5:8B:42:F7 X509v3 Authority Key Identifier: keyid:D5:5D:21:99:D3:9A:BA:90:16:F4:BF:2D:78:C7:27:DF:F5:8B:42:F7
root:/data# (umask 066;openssl genrsa -out test.key1024) # 生成私钥 Generating RSA privatekey, 1024 bit long modulus ................++++++ .......................++++++ e is65537 (0x10001) root:/data# openssl req -new -key test.key -out test.csr # 生成csr证书申请文件 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:beijin Locality Name (eg, city) [Default City]:changping Organization Name (eg, company) [Default Company Ltd]:jindong Organizational Unit Name (eg, section) []:wuliu Common Name (eg, your name or your server's hostname) []:www.jd.com Email Address []:
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: root:/data# scp test.csr 172.22.50.53:/etc/pki/CA/certs/test.csr # 将证书传给客户端
[root@localhost CA]# cd [root@localhost ~]# cd .ssh -bash: cd: .ssh: No such file or directory [root@localhost ~]# mkdir .ssh [root@localhost ~]# cd .ssh [root@localhost .ssh]# [root@localhost .ssh]# tree . └── known_hosts