一般情况下,如果能找到可用的证书,就可以直接使用,只不过会因证书的某些信息不正确或与部署证书的主机不匹配而导致浏览器提示证书无效,但这并不影响使用。

需要手工生成证书的情况有:

  • 找不到可用的证书
  • 需要配置双向SSL,但缺少客户端证书
  • 需要对证书作特别的定制
    首先,无论是在Linux下还是在Windows下的Cygwin中,进行下面的操作前都须确认已安装OpenSSL软件包。
1. 创建根证书密钥文件(自己做CA)root.key:
  openssl genrsa -des3 -out root.key

输出:

Generating RSA private key, 512 bit long modulus ………………++++++++++++
…++++++++++++ e is 65537 (0×10001) Enter pass phrase for root.key: ←
输入一个新密码 Verifying – Enter pass phrase for root.key: ← 重新输入一遍密码

2. 创建根证书的申请文件root.csr:
openssl req -new -key root.key -out root.csr

输出:

Enter pass phrase for root.key: ← 输入前面创建的密码 You are about to be asked
to enter information that will be incorporated into 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
blank For some fields there will be a default value, If you enter ‘.’,
the field will be left blank. —– Country Name (2 letter code) [AU]:CN
← 国家代号,中国输入CN State or Province Name (full name) [Some-State]:BeiJing
← 省的全名,拼音 Locality Name (eg, city) []:BeiJing ← 市的全名,拼音 Organization
Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入 Common Name (eg,
YOUR name) []: ← 此时不输入 Email Address []:admin@mycompany.com ←
电子邮箱,可随意填

Please enter the following ‘extra’ attributes to be sent with your
certificate request A challenge password []: ← 可以不输入 An optional
company name []: ← 可以不输入

3. 创建一个自当前日期起为期十年的根证书root.crt:
openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crt

输出内容为:

Signature ok subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany
Corp./emailAddress=admin@mycompany.com Getting Private key Enter pass
phrase for root.key: ← 输入前面创建的密码

4. 创建服务器证书密钥server.key:
openssl genrsa -des3 -out server.key 2048

输出内容为:

Generating RSA private key, 2048 bit long modulus ….+++
……………………………………………+++ e is 65537 (0×10001)

运行时会提示输入密码,此密码用于加密key文件(参数des3便是指加密算法,当然也可以选用其他你认为安全的算法.),以后每当需读取此文件(通过openssl提供的命令或API)都需输入口令.如果觉得不方便,也可以去除这个口令,但一定要采取其他的保护措施!
去除key文件口令的命令:

openssl rsa -in server.key -out server.key

5.创建服务器证书的申请文件server.csr:
openssl req -new -key server.key -out server.csr

输出内容为:

You are about to be asked to enter information that will be
incorporated into 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 blank For some fields there will
be a default value, If you enter ‘.’, the field will be left blank. —–
Country Name (2 letter code) [AU]:CN ← 国家名称,中国输入CN State or Province
Name (full name) [Some-State]:BeiJing ← 省名,拼音 Locality Name (eg, city)
[]:BeiJing ← 市名,拼音 Organization Name (eg, company) [Internet Widgits
Pty Ltd]:MyCompany Corp. ← 公司英文名 Organizational Unit Name (eg,
section) []: ← 可以不输入 Common Name (eg, YOUR name) []:www.mycompany.com
← 服务器主机名,若填写不正确,浏览器会报告证书无效,但并不影响使用 Email Address
[]:admin@mycompany.com ← 电子邮箱,可随便填

Please enter the following ‘extra’ attributes to be sent with your
certificate request A challenge password []: ← 可以不输入 An optional
company name []: ← 可以不输入

6.创建自当前日期起有效期为期两年的服务器证书server.crt:
openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in server.csr -out server.crt

输出内容为:

Signature ok subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany
Corp./CN=www.mycompany.com/emailAddress=admin@mycompany.com Getting CA
Private Key Enter pass phrase for root.key: ← 输入前面创建的密码

7. 创建客户端证书密钥文件client.key:
openssl genrsa -des3 -out client.key 2048

输出内容为:

Generating RSA private key, 2048 bit long modulus
………………………………………………………………………………+++
……………………………………………………………………………………………………….+++ e is 65537 (0×10001) Enter
pass phrase for client.key: ← 输入一个新密码 Verifying – Enter pass phrase
for client.key: ← 重新输入一遍密码

8. 创建客户端证书的申请文件client.csr:
openssl req -new -key client.key -out client.csr

输出内容为:

Enter pass phrase for client.key: ← 输入上一步中创建的密码 You are about to be
asked to enter information that will be incorporated into 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 blank For some fields there will be a default value, If you
enter ‘.’, the field will be left blank. —– Country Name (2 letter
code) [AU]:CN ← 国家名称,中国输入CN State or Province Name (full name)
[Some-State]:BeiJing ← 省名称,拼音 Locality Name (eg, city) []:BeiJing ←
市名称,拼音 Organization Name (eg, company) [Internet Widgits Pty
Ltd]:MyCompany Corp. ← 公司英文名 Organizational Unit Name (eg, section)
[]: ← 可以不填 Common Name (eg, YOUR name) []:Lenin ← 自己的英文名,可以随便填 Email
Address []:admin@mycompany.com ← 电子邮箱,可以随便填

Please enter the following ‘extra’ attributes to be sent with your
certificate request A challenge password []: ← 可以不填 An optional
company name []: ← 可以不填

9. 创建一个自当前日期起有效期为两年的客户端证书client.crt:
openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in client.csr -out client.crt

输出内容为:

Signature ok subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany
Corp./CN=www.mycompany.com/emailAddress=admin@mycompany.com Getting CA
Private Key Enter pass phrase for root.key: ← 输入上面创建的密码

10. 将客户端证书文件client.crt和客户端证书密钥文件client.key合并成客户端证书安装包client.pfx:
openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx

输出内容为:

Enter pass phrase for client.key: ← 输入上面创建的密码 Enter Export Password: ←
输入一个新的密码,用作客户端证书的保护密码,在客户端安装证书时需要输入此密码 Verifying – Enter Export
Password: ← 确认密码

保存生成的文件备用,其中server.crt和server.key是配置单向SSL时需要使用的证书文件,client.crt是配置双向SSL时需要使用的证书文件,client.pfx是配置双向SSL时需要客户端安装的证书文件

.crt文件和.key可以合到一个文件里面,把2个文件合成了一个.pem文件(直接拷贝过去就行了)

11. 生成pem文件
  cat server.crt server.key |tee server.pem


[宝塔上部署证书](https://www.bt.cn/bbs/thread-704-1-1.html) [https://www.bt.cn/bbs/thread-704-1-1.html](https://www.bt.cn/bbs/thread-704-1-1.html)

生成自签名ssl证书相关推荐

  1. 离线部署nginx到redhat/centos,从安装环境到部署dist包全家桶(附带生成自签名SSL证书)

    一.准备nginx环境 先检查gcc .PCRE .zlib.openssl.nginx是否已经安装. gcc version rpm -qa pcre yum list installed | gr ...

  2. linux系统自签发免费ssl证书,为nginx生成自签名ssl证书

    安装nginx可参考: nginx重新编译支持ssl可参考: 接下来手动配置ssl证书: 自己手动颁发证书的话,那么https是不被浏览器认可的,就是https上面会有一个大红叉 下面是手动颁发证书的 ...

  3. 自己制作ssl证书:自己签发免费ssl证书,为nginx生成自签名ssl证书

    Nginx支持多域名ssl证书 导读: 昨天凌晨将公司旗下的另外一个域名也升级成通过ssl证书登录的形式,那里料到过程竟然非常曲折,原因是nginx如果编译的时候使用openssl如果没有添加enab ...

  4. keytool生成证书_创建自签名ssl证书,Java生产jks证书

    一.创建自签名ssl证书 下载openssl软件: https://pan.baidu.com/s/1Zy4W7pqSO8caoR_R5pF3DQ  #提取码:bjd4 设置环境变量 进入openss ...

  5. 自签名SSL证书有风险吗?

    自签名SSL证书的技术操作与自签名证书生成在互联网上有许多教程,许多用户想节省点银子,便选择自签名SSL证书,又担心自签名SSL证书会给网站带来风险.针对这一问题,我们必然要具体问题具体分析. 首先来 ...

  6. 网络安全--keytool CA签名SSL证书(收费)

    本文主要介绍keytool CA签名SSL证书(收费),点击查看keytool自签名SSL证书(免费)以及私钥签名.公钥验签流程 最近给银行做一个系统,虽说是给行内使用的,但是系统要同时支持内外网方式 ...

  7. https 自签名SSL证书

    介绍 TLS或称传输层安全性,及其前身SSL(代表安全套接字层)是用于将正常流量包装在受保护的加密包装中的Web协议. 使用这种技术,服务器可以在服务器和客户端之间安全地发送流量,而不会被外部各方拦截 ...

  8. 网络--keytool自签名SSL证书(免费)以及私钥签名、公钥验签

    本文主要介绍keytool自签名SSL证书(免费)以及私钥签名.公钥验签流程,点击查看keytool CA签名SSL证书(收费) 最近给银行做一个系统,虽说是给行内使用的,但是系统要同时支持内外网方式 ...

  9. 【SSL】ssl证书简介、ssl证书生成工具与ssl证书生成步骤

    ssl证书简介.ssl证书生成工具与ssl证书生成步骤 一.ssl证书是什么? 二.ssl证书生成工具有哪些? 2.1.工具一:CFSSL 2.2.工具二:OpenSSL 2.3.工具三:XCA 三. ...

最新文章

  1. VS Code搭建C/C++开发环境超详细教程
  2. [JUC-5]ConcurrentHashMap源码分析JDK8
  3. 解决1px的border在移动端变粗的问题
  4. 计算机考试一级考试基础知识,2016计算机一级考试msoffice基础知识
  5. 搭建eclipse版的ssm+maven+tk.mybatis+redis及mybatis+spring多数据源配置集成的demo
  6. 【干货】Linux中实用但很小众的11个炫酷终端命令
  7. kafka topic常用命令
  8. u盘启动 联想一体机_关于联想扬天B41-30-NTZ(L)使用U盘重装Win10系统的详细步骤
  9. eclipse调试报错,无法进入类的解决办法
  10. 【3D游戏建模】3D建模师的发展前景
  11. linux 删除N天文件
  12. html网页中两侧浮动广告怎么做,网页两侧浮动广告图片js代码
  13. 【工具】Movielens数据集详细介绍
  14. 职场感悟.Video.人生各自精彩,谁说人生是一场马拉松的?
  15. Postgresql杂谈 04—Postgresql中的五种常规索引
  16. Q:python编码
  17. nginx转发http请求
  18. 离线数仓搭建_15_ADS层数据构建
  19. GitLab 小白入手教程
  20. 老男孩读PCIe之一:从PCIe速度说起

热门文章

  1. arcgis悬挂点修改_ArcGis拓扑的那些事儿(拓扑应用过程三)
  2. php5.6 交叉编译,Cross-compile - 龙芯开源社区
  3. java 二进制 base64编码_java 按字节读写二进制文件(Base64编码解码)
  4. html 定义函数调用函数,请问HTML function函数怎么定义和调用?
  5. 四、MapReduce和Yarn基本架构
  6. 四十、Linux和ViM的使用
  7. keras从入门到放弃(十七)使用预训练网络VGG迁移学习
  8. 岗位内推 | 阿里巴巴达摩院决策智能实验室招聘全职/实习生
  9. CVPR 2020 | 自适应聚合网络AANet:更高效的立体匹配
  10. 【天池赛事】零基础入门语义分割-地表建筑物识别 Task3:网络模型结构发展