Linux搭建CA服务

本文详细介绍了在Linux系统中搭建CA服务的过程,包括安装工具、配置文件、创建CA及客户端证书,以及证书吊销和管理的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

什么是CA认证?

CA认证,即CA认证机构,为电子签名相关各方提供真实性、可靠性验证的行为。

什么是CA证书?

证书实际是由证书签证机关(CA)签发的对用户的公钥的认证。

CA证书类型?

  • 证书颁发机构自签名证书
  • 服务器证书
  • 用户证书

Linux系统如何搭建CA服务?

1.安装相关工具:openssl
yum install openssl -y
2.openssl相关配置文件:/etc/pki/tls/openssl.cnf
指定默认使用的CA

[ ca ]
default_ca      = CA_default            # The default ca section
CA的相关配置
[ CA_default ]
dir             = /etc/pki/CA               ​    ​    ​    ​# Where everything is kept,CA的工作目录
certs           = $dir/certs                ​    ​         # Where the issued certs are kept,已经颁发的证书存放目录
crl_dir         = $dir/crl                  ​    ​        ​  ​ # Where the issued crl are kept,证书吊销列表存放目录
database        = $dir/index.txt            ​      ​ # database index file,证书的索引数据库

new_certs_dir   = $dir/newcerts             ​   # default place for new certs,新证书存放目录
certificate     = $dir/cacert.pem           ​    ​ # The CA certificate,CA证书
serial          = $dir/serial               ​    ​    ​    ​# The current serial number,当前证书编号
crlnumber       = $dir/crlnumber            ​  # the current crl number,当前吊销证书编号

crl             = $dir/crl.pem              ​    ​    ​   # The current CRL,当前的吊销证书
private_key     = $dir/private/cakey.pem # The private key,CA私钥
RANDFILE        = $dir/private/.rand        ​ # private random number file,随机文件

default_days    = 365                       ​    ​    ​# how long to certify for,证书有效期
default_crl_days= 30                        ​    ​    ​# how long before next CRL,发布证书 吊销列表的周期
default_md      = sha256                    ​    ​  # use SHA-256 by default,算法
preserve        = no                                    # keep passed DN ordering

policy          = policy_match    ​    ​    ​    ​    ​    ​#选择使用的策略类型
\# For the CA policy
[ policy_match ]    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​#第一种策略
countryName             = match    ​    ​    ​    ​     ​#是否匹配国家
stateOrProvinceName     = match    ​    ​    ​    #是否匹配省

organizationName        = match    ​    ​    ​    ​  #是否匹配组织名称
organizationalUnitName  = optional    ​    ​   #是否单元名称
commonName              = supplied    ​    ​    ​  #通用名
emailAddress            = optional    ​    ​    ​    ​   #邮箱

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

3.创建CA

(1)创建索引数据库文件和指定证书编号 ​ ​ ​

touch /etc/pki/CA/index.txt
echo 01 >/etc/pki/CA/serial

(2)CA自签名证书

生成私钥:

(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

生成自签名证书:

openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365

Linux搭建CA服务
(3)客户端创建申请文件
生成客户端私钥:

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

生成申请文件:

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

Linux搭建CA服务
将生成的申请文件发送到CA颁发服务器

scp app.csr 192.168.128.130:/etc/pki/CA/

(4)CA服务器为客户端颁发证书

openssl ca -in app.csr -out certs/app.crt -days 100

Linux搭建CA服务
(5)将生成的证书发送给申请的客户端

 scp certs/app.crt 192.168.128.129:

证书吊销
生成吊销证书序号文件

echo 01 >crlnumber

吊销证书

openssl ca -revoke /etc/pki/CA/newcerts/01.pem

生成吊销列表

openssl ca -gencrl -out /etc/pki/CA/crl.pem

注意事项:
1.必须要提前创建证书数据库引导文件/etc/pki/CA/index.txt
2.指定证书编号,证书颁发完成后会自动更新证书序号

转载于:https://blog.51cto.com/zchui/2325311

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值