千家信息网

Centos8上搭建CA证书

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,Centos8上搭建CA证书要在centos8上实现自建CA证书要利用openssl,首先查看openssl配置文件[root@Centos8 data]#vim /etc/pki/tls/opens
千家信息网最后更新 2026年11月01日Centos8上搭建CA证书

Centos8上搭建CA证书

要在centos8上实现自建CA证书要利用openssl,首先查看openssl配置文件

[root@Centos8 data]#vim /etc/pki/tls/openssl.cnf[ CA_default ]dir             = /etc/pki/CA           # Where everything is keptcerts           = $dir/certs            # Where the issued certs are keptcrl_dir         = $dir/crl              # Where the issued crl are keptdatabase        = $dir/index.txt        # database index file.#unique_subject = no                    # Set to 'no' to allow creation of                                        # several certs with same subject.new_certs_dir   = $dir/newcerts         # default place for new certs.certificate     = $dir/cacert.pem       # The CA certificateserial          = $dir/serial           # The current serial numbercrlnumber       = $dir/crlnumber        # the current crl number                                        # must be commented out to leave a V1 CRLcrl             = $dir/crl.pem          # The current CRLprivate_key     = $dir/private/cakey.pem# The private keyRANDFILE        = $dir/private/.rand    # private random number filex509_extensions = usr_cert              # The extensions to add to the cert  

这段配置代表了CA的目录结构,和每个目录是放置什么文件,有什么作用,做出了一些解释。
因为centos7上CA相关的目录是系统自带的,但是centos8上只有CA家目录,也就是 /etc/pki/CA,这个目录,所以参考centos7上的目录结构来新建CA相关目录
centos7上目录结构:

[root@centos7 ~]#cd /etc/pki/CA/  [root@centos7 CA]#tree .├── certs├── crl├── newcerts└── private4 directories, 0 files

在centos8上运行:

[root@Centos8 data]mkdir -p /etc/pki/CA/{certs,crl,newcerts,private}

cd private/
生成私钥:

(umask 077; openssl genrsa -out cakey.pem 4096)

生成自签的CA证书:

openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650

[root@Centos8 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 incorporatedinto 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 blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:beijingLocality Name (eg, city) [Default City]:beijing  Organization Name (eg, company) [Default Company Ltd]:wj02Organizational Unit Name (eg, section) []:M39  Common Name (eg, your name or your server's hostname) []:www.wj02.comEmail Address []:[root@Centos8 CA]#

要输入的内容依次为:

输入:(国家代码)CN
输入:(所在省份)beijing
输入:(所在城市)beijing
输入:(公司名称)wj02
输入:(部门名称)M39
输入:(用户名或主机名)www.wj02.com
输入:(邮箱地址)可留空,直接回车
根据提示,输入相应信息即可。

查看自签证书详细内容命令:

[root@Centos8 CA]#openssl x509 -in cacert.pem -noout -textCertificate:    Data:        Version: 3 (0x2)        Serial Number:            43:cf:75:6e:3a:94:cc:98:38:c1:48:c7:d9:37:70:e3:fb:71:19:e6        Signature Algorithm: sha256WithRSAEncryption        Issuer: C = CN, ST = beijing, L = beijing, O = wj02, OU = M39, CN = www.wj02.com        Validity            Not Before: Nov 12 06:50:53 2019 GMT            Not After : Nov  9 06:50:53 2029 GMT        Subject: C = CN, ST = beijing, L = beijing, O = wj02, OU = M39, CN = www.wj02.com        Subject Public Key Info:            Public Key Algorithm: rsaEncryption                RSA Public-Key: (4096 bit)                Modulus:

可以看到证书的详细信息
然后在另一台机器,因为要重新生成私钥,所以要至少两台机器。
生成私钥:

(umask 077; openssl genrsa -out app.key 1024)

生成ca证书请求文件:

openssl req -new -key app.key -out app.csr

值得注意的是,有三项,就是国家,所在省,公司名称这三项一定要和自签证书一致
因为在配置文件里有规定:

policy          = policy_match# For the CA policy[ policy_match ]countryName             = matchstateOrProvinceName     = matchorganizationName        = matchorganizationalUnitName  = optionalcommonName              = suppliedemailAddress            = optional

这三项是强制一样的,当然也可以修改配置文件
利用scp将cs请求文件发送到server

scp test.csr 192.168.38.120:/etc/pki/CA

接下来就是server给test.csr签署证书:

[root@Centos8 CA]#openssl ca -in test.csr -out test.crt -days 365Using configuration from /etc/pki/tls/openssl.cnf140011092936512:error:02001002:system library:fopen:No such file or directory:crypto/bio/bss_file.c:72:fopen('/etc/pki/CA/index.txt','r')140011092936512:error:2006D080:BIO routines:BIO_new_file:no such file:crypto/bio/bss_file.c:79:[root@Centos8 CA]#

额,报错了?莫慌,这个是因为缺少文件导致的,报错信息可以看到,我们缺少/etc/pki/CA/index.txt这个文件

touch /etc/pki/CA/index.txt

再次运行:

[root@Centos8 CA]#openssl ca -in test.csr -out test.crt -days 365Using configuration from /etc/pki/tls/openssl.cnfCan't open /etc/pki/CA/index.txt.attr for reading, No such file or directory140275620157248:error:02001002:system library:fopen:No such file or directory:crypto/bio/bss_file.c:72:fopen('/etc/pki/CA/index.txt.attr','r')140275620157248:error:2006D080:BIO routines:BIO_new_file:no such file:crypto/bio/bss_file.c:79:/etc/pki/CA/serial: No such file or directoryerror while loading serial number140275620157248:error:02001002:system library:fopen:No such file or directory:crypto/bio/bss_file.c:72:fopen('/etc/pki/CA/serial','r')140275620157248:error:2006D080:BIO routines:BIO_new_file:no such file:crypto/bio/bss_file.c:79:[root@Centos8 CA]#

还错?现在是缺少/etc/pki/CA/serial这个文件,但是这个文件不能是空文件,它里面是有东西的。
查看配置文件我们发现这个文件是记录证书序列号的,所以,,,,

[root@Centos8 CA]#echo 01 > /etc/pki/CA/serial

我们给他指定一个序列号不就好啦
再次运行

[root@Centos8 CA]#openssl ca -in test.csr -out test.crt -days 365Using configuration from /etc/pki/tls/openssl.cnfCan't open /etc/pki/CA/index.txt.attr for reading, No such file or directory140145607882560:error:02001002:system library:fopen:No such file or directory:crypto/bio/bss_file.c:72:fopen('/etc/pki/CA/index.txt.attr','r')140145607882560:error:2006D080:BIO routines:BIO_new_file:no such file:crypto/bio/bss_file.c:79:Check that the request matches the signatureSignature okCertificate Details:        Serial Number: 1 (0x1)        Validity            Not Before: Nov 12 07:26:38 2019 GMT            Not After : Nov 11 07:26:38 2020 GMT        Subject:            countryName               = CN            stateOrProvinceName       = beijing            organizationName          = wj02            organizationalUnitName    = M39            commonName                = www.wj02.com        X509v3 extensions:            X509v3 Basic Constraints:                 CA:FALSE            Netscape Comment:                 OpenSSL Generated Certificate            X509v3 Subject Key Identifier:                 A2:A8:2B:77:95:4C:E8:80:0C:50:DF:0E:89:ED:17:94:4E:DF:AC:71            X509v3 Authority Key Identifier:                 keyid:D8:E4:A8:09:2A:2D:13:39:29:63:83:5E:CF:8D:EA:99:A6:79:0B:67Certificate is to be certified until Nov 11 07:26:38 2020 GMT (365 days)Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]yWrite out database with 1 new entriesData Base Updated[root@Centos8 CA]#

成功。嗯,记得输入两次y
到此,自建CA证书生成完成,可以使用了。

文件 输入 证书 目录 生成 配置 信息 名称 所在 结构 运行 公司 内容 再次 国家 就是 序列 序列号 机器 签证 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 中国互联网科技工作委员会毛军 互联网核心科技是什么 互联网的科技创新 极限挑战互联网科技 润盈互联网科技 长亮科技 互联网金融 成都狮子座互联网科技 哈尔滨新华互联网科技学院 世界互联网科技公司市值排名 浙江互联网科技研学营 武汉健翔互联网络科技有限公司 苏州五指互联网络科技有限 科技类公司包括互联网吗 中国科技创新与世界互联网大会 互联网数据科技专业 深圳互联网科技的发展 互联网企业科技类企业如何做账 城市宝互联网科技有限公司 易企秀互联网科技是做什么的 互联网高科技行业有哪些企业 广州淘业互联网络科技 互联网金融监管科技数据 鸠鸠互联网科技 菲比寻常互联网科技 互联网科技网站 互联网科技博主是什么意思 辽宁互联网新科技 想开互联网科技公司怎么样 特约风豹互联网科技为什么扣费 山东亿川互联网科技有限责任公司
0