在Linux下,我们进行下面的操作前都须确认已安装OpenSSL软件包。

1.创建根证书密钥文件root.key:

[root@mrlapulga:/etc/pki/CA/private]#openssl genrsa -des3 -out root.key 1024
Generating RSA private key, 1024 bit long modulus
...............................................................++++++
..........++++++
e is 65537 (0x10001)
Enter pass phrase for root.key:    <--输入一个密码
Verifying - Enter pass phrase for root.key:    <--再次输入密码

2.创建根证书的申请文件root.csr:

[root@mrlapulga:/etc/pki/CA]#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) [XX]:CN    <--输入国家名
State or Province Name (full name) []:BeiJing    <--输入省份
Locality Name (eg, city) [Default City]:haidian    <--输入城市名
Organization Name (eg, company) [Default Company Ltd]:mrlapulga    <--输入公司名
Organizational Unit Name (eg, section) []:    <--可不输入
Common Name (eg, your name or your server's hostname) []:    <--可不输入
Email Address []:mrlapulga@126.com    <--输入邮件地址
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:    <--可不输入
An optional company name []:    <--可不输入

3.创建一个为期十年的根证书root.crt:

[root@mrlapulga:/etc/pki/CA]#openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey private/root.key -in root.csr -out root.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=haidian/O=mrlapulga/emailAddress=mrlapulga@126.com
Getting Private key
Enter pass phrase for private/root.key:    <--输入之前创建的密码

4.创建服务器证书密钥server.key:

[root@mrlapulga:/etc/pki/CA/private]#openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 2014 bit long modulus
............+++
................................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:    <--输入一个密码
Verifying - Enter pass phrase for server.key:    <--再次输入密码

5.创建服务器证书的申请文件server.csr:

[root@mrlapulga:/etc/pki/CA]#openssl req -new -key private/server.key -out server.csr
Enter pass phrase for private/server.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) [XX]:CN    <--输入国家名
State or Province Name (full name) []:BeiJing    <--输入省份
Locality Name (eg, city) [Default City]:haidian    <--输入城市名
Organization Name (eg, company) [Default Company Ltd]:mrlapulga    <--输入公司名
Organizational Unit Name (eg, section) []:    <--可不输入
Common Name (eg, your name or your server's hostname) []:    <--可不输入
Email Address []:mrlapulga@126.com    <--输入邮件地址
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:    <--可不输入
An optional company name []:    <--可不输入

6.创建一个为期一年的服务器证书server.crt:

[root@mrlapulga:/etc/pki/CA]#openssl x509 -req -days 365 -sha1 -extensions v3_req -CA root.crt -CAkey private/root.key -CAcreateserial -in server.csr -out server.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=haidian/O=mrlapulga/emailAddress=mrlapulga@126.com
Getting CA Private Key
Enter pass phrase for private/root.key:    <--输入之前创建的密码

7.创建客户端证书密钥文件client.key:

[root@mrlapulga:/etc/pki/CA/private]#openssl genrsa -des3 -out client.key 1024
Generating RSA private key, 1024 bit long modulus
..............................++++++
..................................................++++++
e is 65537 (0x10001)
Enter pass phrase for client.key:    <--输入一个密码
Verifying - Enter pass phrase for client.key:   <--再次输入密码

8.创建客户端证书的申请文件client.csr:

[root@mrlapulga:/etc/pki/CA]#openssl req -new -key private/client.key -out client.csr
Enter pass phrase for private/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) [XX]:CN    <--输入国家名
State or Province Name (full name) []:BeiJing    <--输入省份
Locality Name (eg, city) [Default City]:haidian    <--输入城市名
Organization Name (eg, company) [Default Company Ltd]:mrlapulga    <--输入公司名  
Organizational Unit Name (eg, section) []:    <--可不输入
Common Name (eg, your name or your server's hostname) []:    <--可不输入
Email Address []:mrlapulga@126.com    <--输入邮件地址
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:    <--可不输入
An optional company name []:    <--可不输入

9.创建一个有效期为一年的客户端证书client.crt:

[root@mrlapulga:/etc/pki/CA]#openssl x509 -req -days 365 -sha1 -extensions v3_req -CA root.crt -CAkey private/root.key -CAcreateserial -in client.csr -out client.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=haidian/O=mrlapulga/emailAddress=mrlapulga@126.com
Getting CA Private Key
Enter pass phrase for private/root.key:    <--输入之前创建的密码

10.现在可将客户端证书文件client.crt和客户端证书密钥文件client.key合并为客户端的client.pfx安装包文件:

[root@mrlapulga:/etc/pki/CA]#openssl pkcs12 -export -in client.crt -inkey private/client.key -out client.pfx
Enter pass phrase for private/client.key:    <--输入之前创建的密码
Enter Export Password:    <--创建一个新密码
Verifying - Enter Export Password:    <--确认密码

client.pfx是配置双向SSL时需要客户端安装的证书文件。

SSL证书的生成方法的更多相关文章

  1. Https系列之一:https的简单介绍及SSL证书的生成

    Https系列会在下面几篇文章中分别作介绍: 一:https的简单介绍及SSL证书的生成二:https的SSL证书在服务器端的部署,基于tomcat,spring boot三:让服务器同时支持http ...

  2. SSL证书的生成

    openssl工具下载路径:链接:https://pan.baidu.com/s/1o0-s8OplHZt55Cio2HmjVA 密码:u759 1.使用openssl工具生成一个RSA秘钥      ...

  3. 让GIt忽略SSL证书错误的方法

    当你通过HTTPS访问Git远程仓库,如果服务器的SSL证书未经过第三方机构签署,那么Git就会报错.这是十分合理的设计,毕竟未知的没有签署过的证书意味着很大安全风险.但是,如果你正好在架设Git服务 ...

  4. Nginx配置SSL证书部署HTTPS方法

    1.申请域名,绑定服务器ip(我申请的是阿里云服务器,以下就此为例) 2.可以在阿里云上免费申请SSL证书(下载证书,后续会用到) 3.在服务器中配置证书 在服务器上安装Nginx 将下载好的证书上传 ...

  5. TortoiseGit 访问https远程仓库,上报SSL证书错误解决方法

    报错 在使用TortoiseGit时,clone自己搭建的gitlab报如错SSL certificate problem: self signed certificate 原因:自行搭建的gitla ...

  6. CentOS 7.2 下nginx SSL证书部署的方法(使用crt以及key 配置)

    转自:https://www.jb51.net/article/107350.htm 环境 系统环境:CentOS6.7 nginx version: nginx/1.8.1 证书 ? 1 2 3 # ...

  7. 生成ssl证书文件

    网上关于生成SSL证书文件的方法有很多,但我查了几个,发现有或多或少的错误,如下我图文并茂的展示,亲测无任何问题,分享给大家,谢谢. 1.创建根证书密钥文件(自己做CA)root.key openss ...

  8. 如何在 CentOS 7 上生成 SSL 证书为 Nginx 加密

    本文首发:开发指南:如何在 CentOS 7 上安装 Nginx Let’s Encrypt 是由 Internet Security Research Group (ISRG) 开发的一个自由.自动 ...

  9. http跳转https方法:百度云如何让http自动跳转到https【免费SSL证书使用FAQ】

    之前的一篇文章已经给大家提供了免费SSL证书的申请方法,这一篇文章是告诉大家在使用免费的SSL证书时可能会遇到的问题[怎么让http自动跳转到https以及http与https同时使用]的解决方法. ...

随机推荐

  1. h5标签基础 table表格标签

    一.表格的定义:用于有规范的显示数据. 二.基本组成: 行<tr>/列<td>/表头<caption>/表标题<th> eg: <table> ...

  2. Struts2学习笔记①

    Struts2 学习笔记① 所有的程序学习都从Hello World开始,今天先跟着书做一个HW的示例. Struts2是一套MVC框架,使用起来非常方便,接触到现在觉得最麻烦的地方是配置文件.我的一 ...

  3. react学习总结

    http://www.runoob.com/react/react-tutorial.html一般先看一些中文的简单的介绍和一些基本概念http://reactjs.cn/react/docs/get ...

  4. 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字

    2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 97 ...

  5. 获取3个月前的时间(获取某一天的时间 NSDate)

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; ...

  6. swift -- as / 扩展

    一.使用 可选链式 调用代替强制展开 //当声明一个属性时,将属性类型设置为可选类型: 好处: 当可选类型的属性被赋予初始值时,系统调用初始值;当可选类型属性没有赋予初始值时,系统只会调用失败;如果属 ...

  7. win8和ubuntu双系统

    硬盘安装的话只要分够内存和做好开机启动项就好了,u盘安装要注意分区(挂载)了推荐: http://wenku.baidu.com/view/5052f19b51e79b8968022623.html ...

  8. 使用RecyclerView实现的分组列表。

    项目介绍: StickyHeaders使用RecyclerView实现的分组列表

  9. Thread.join()的使用

    代码清单: package com.baidu.nuomi.concurrent; import java.util.concurrent.TimeUnit; /** * Created by son ...

  10. 【转】JavaScript 之arguments、caller 和 callee 介绍

    1.前言 arguments, caller ,   callee 是什么? 在JavaScript 中有什么样的作用?本篇会对于此做一些基本介绍. 本文转载自:http://blog.csdn.ne ...