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 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章