Openssl 设置 双向认证证书的过程

Openssl 设置 双向认证证书的过程


openssl的安装

安装openssl
大部分操作系统都会带 openssl 只是版本略有不同.
因为不带openssl 连基本的openssh 可能都没法用.
安装方法
yum install openssl -y 

查看版本:
openssl version
OpenSSL 1.1.1k  FIPS 25 Mar 2021
OpenEuler2203上面的版本为:
openssl version
OpenSSL 1.1.1m  14 Dec 2021

证书创建过程

先创建 key 
mkdir -p /cert 
cd /cert 
openssl genrsa -out ca.key 4096
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/C=CN/ST=SD/L=JN/O=JNXLH/OU=JNXLH"

# 创建好 ca 之后 需要创建 服务端证书
openssl req -new -nodes -keyout server.key -out server.csr -subj "/C=CN/ST=SD/L=JN/O=JNXLH/OU=JNXLH/CN=10.110.139.121,10.110.139.122"
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 36000 -extensions v3_req
# 查看证书
openssl x509 -text -in server.crt 
# 生成pfx
openssl pkcs12 -password pass:Testxxxxxxxx -export -out server.pfx -inkey server.key -in server.crt

# 创建客户端证书
openssl genrsa -out test01.key 4096
openssl req -new -key test01.key -out test01.csr -subj "/C=CN/ST=SD/L=JN/O=JNXLH/OU=JNXLH/CN=test01"
openssl x509 -req -days 36500 -CA ca.crt -CAkey ca.key -CAcreateserial  -in test01.csr -out test01.crt
openssl pkcs12 -password pass:Testxxxxxxxx -export -out test01.pfx -inkey test01.key -in test01.crt
# 查看一下证书
openssl x509 -text -in test01.crt

多用户创建

for i in {01..99}
do
openssl genrsa -out test${i}.key 4096
openssl req -new -key test${i}.key -out test${i}.csr -subj "/C=CN/ST=SD/L=JN/O=JNXLH/OU=JNXLH/CN=test${i}"
openssl x509 -req -days 36500 -CA ca.crt -CAkey ca.key -CAcreateserial  -in test${i}.csr -out test${i}.crt
openssl pkcs12 -password pass:Testxxxxxxxx -export -out test${i}.pfx -inkey test${i}.key -in test${i}.crt
done 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章