略
shell> yum list installed | grep openssl
shell> yum install -y openssl
shell> vim /etc/pki/tls/openssl.cnf
将 policy = policy_match 改为 policy = policy_anything
生成证书索引数据库文件 (默认为空文件)
shell> touch /etc/pki/CA/index.txt
指定第一个颁发证书的序列号
shell> echo 01 > /etc/pki/CA/serial
shell> cd /etc/pki/CA/
shell> openssl genrsa -out private/cakey.pem 2048
shell> chmod 400 private/cakey.pem
shell> cd /etc/pki/CA/
shell> openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
-new: 生成新证书签署请求-x509: 专用于CA生成自签证书-key : 指向私钥文件-days :证书的有效期限-out : 证书的保存路径shell> openssl genrsa -out com.mydomain.key 2048
shell> openssl req -new -key com.mydomain.key -out com.mydomain.csr
shell> cd /etc/httpd/cert.d/
shell> openssl ca -in com.mydomain.csr -out com.mydomain.crt -days 360
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 2 (0x2)
Validity
Not Before: Sep 4 12:28:26 2022 GMT
Not After : Aug 30 12:28:26 2023 GMT
Subject:
countryName = CN
stateOrProvinceName = BEIJING
localityName = BEIJING
organizationName = COMPANY
organizationalUnitName = SECTION
commonName = mydomain.com
emailAddress = admin@mydomain.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
41:E1:70:F4:38:7E:88:92:E2:6D:8C:6B:45:FC:B9:26:DF:D9:1C:5B
X509v3 Authority Key Identifier:
keyid:B6:12:B9:F5:91:13:D1:F7:90:09:0F:5A:49:2C:9E:5B:D1:0B:B9:DC
Certificate is to be certified until Aug 30 12:28:26 2023 GMT (360 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
-cert : 指向CA证书。不指定该参数时,默认指向/etc/pki/CA/cacert.pem。-keyfile : 指向CA KEY。不指定该参数时,默认指向/etc/pki/CA/private/cakey.pem。shell> openssl genrsa -out com.mydomain.key 2048
shell> openssl req -new -x509 -key com.mydomain.key -out com.mydomain.crt -days 365
-x509: 用于生成自签证书这种情况一般发生在你之前生成过一样的证书,又想重新生成一模一样的证书。
解决方法有2种:
/etc/pki/CA/index.txt.attr,将 unique_subject = yes改为 unique_subject = no。一旦修改,无法再修改回来。/etc/pki/CA/index.txt、/etc/pki/CA/serial及相关文件,并重新创建/etc/pki/CA/index.txt、/etc/pki/CA/serial。