当前位置: 首页 > article >正文

使用OpenSSL生成根证书并自签署证书

生成根CA的私钥和证书

# 生成根 CA 的私钥
[root@developer ssl]# openssl genrsa -out rootCA.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
...+++++
............................................................+++++
e is 65537 (0x010001)# 使用私钥生成根 CA 的证书
[root@developer ssl]# openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt
Country Name (2 letter code) [XX]:CN  # 国家名称(2个字母代码)
State or Province Name (full name) []:JS  # 州或省名
Locality Name (eg, city) [Default City]:KS  # 地点名称
Organization Name (eg, company) [Default Company Ltd]:local  # 组织名称
Organizational Unit Name (eg, section) []:developer  # 组织单位名称
Common Name (eg, your name or your server's hostname) []:Local Developer CA  # 通用名称
Email Address []:

为hello-world.test生成私钥和证书请求文件(CSR)

# 生成 hello-world.test 的私钥
[root@developer ssl]# openssl genrsa -out hello-world.test.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
..........................................................................+++++
.....+++++
e is 65537 (0x010001)# 使用私钥生成证书请求文件
[root@developer ssl]# openssl req -new -key hello-world.test.key -out hello-world.test.csr
Country Name (2 letter code) [XX]:CN  # 国家名称(2个字母代码)
State or Province Name (full name) []:JS  # 州或省名
Locality Name (eg, city) [Default City]:KS  # 地点名称
Organization Name (eg, company) [Default Company Ltd]:local  # 组织名称
Organizational Unit Name (eg, section) []:developer  # 组织单位名称
Common Name (eg, your name or your server’s hostname) []:*.hello-world.test  # 域名
Email Address []:Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

创建证书扩展文件

为了确保为 hello-world.test 签名的证书能够用作服务器身份验证,需要为它创建一个扩展文件。创建一个名为 v3.ext 的文件,并添加以下内容:

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names[alt_names]
DNS.1 = *.hello-world.test
# 如果是IP就使用 IP.1 = 你的IP地址

使用根 CA 的证书为 hello-world.test 签名证书

[root@developer ssl]# openssl x509 -req -in hello-world.test.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out hello-world.test.crt -days 500 -sha256  -extfile v3.ext
Signature ok
subject=C = CN, ST = JS, L = KS, O = local, OU = developer, CN = *.hello-world.test
Getting CA Private Key

此时文件夹内应该有以下文件:

[root@developer ssl]# ll
-rw-r--r--. 1 root root 1318 523 09:59 rootCA.crt
-rw-------. 1 root root 1675 523 09:59 rootCA.key
-rw-r--r--. 1 root root   41 523 10:14 rootCA.srl
-rw-r--r--. 1 root root  253 523 10:13 v3.ext
-rw-r--r--. 1 root root 1322 523 10:14 hello-world.crt
-rw-r--r--. 1 root root  997 523 10:02 hello-world.csr
-rw-------. 1 root root 1679 523 10:00 hello-world.key

宝塔部署

宝塔网站设置中SSL选项选择当前证书,密钥(KEY)中填入hello-world.key的内容,证书(PEM格式)中填入hello-world.crt的内容,最后将rootCA.crt安装到电脑的本地受信任的根证书颁发机构中。

http://www.lryc.cn/news/2384734.html

相关文章:

  • uniapp-商城-62-后台 商品列表(分类展示商品的布局)
  • 初识C++:模版
  • 【Elasticsearch】给所索引创建多个别名
  • Linux入门(九)任务调度
  • 突破认知边界:神经符号AI的未来与元认知挑战
  • Java 处理地理信息数据[DEM TIF文件数据获取高程]
  • 谈谈对dubbo的广播机制的理解
  • 对接钉钉消息样例:DING消息、机器人
  • 003-类和对象(二)
  • 使用Rancher在CentOS 环境上部署和管理多Kubernetes集群
  • Java常用数据结构底层实现原理及应用场景
  • 利用朴素贝叶斯对UCI 的 mushroom 数据集进行分类
  • Linux火墙管理及优化
  • Visual Studio 制作msi文件环境搭建
  • (Java基础笔记vlog)Java中常见的几种设计模式详解
  • C++ vector 深度解析:从原理到实战的全方位指南
  • 鸿蒙进阶——Framework之Want 隐式匹配机制概述
  • antv/g6 图谱封装配置(二)
  • OpenCV CUDA模块图像过滤------用于创建一个最小值盒式滤波器(Minimum Box Filter)函数createBoxMinFilter()
  • 网络抓包命令tcpdump及分析工具wireshark使用
  • linux strace调式定位系统问题
  • femap许可与云计算集成
  • 车载诊断架构 --- 车载诊断有那些内容(上)
  • 【Hadoop】大数据技术之 HDFS
  • 聊一下CSS中的标准流,浮动流,文本流,文档流
  • ATGM332D-F8N22单北斗多频定位导航模块
  • 2024年热门AI趋势及回顾
  • 【信息系统项目管理师】第20章:高级项目管理 - 28个经典题目及详解
  • 3. OpenManus-RL中使用AgentGym建立强化学习环境
  • C++性能测试工具——sysprof的使用