一般情况下,如果能找到可用的证书,就可以直接使用,只不过会因证书的某些信息不正确或与部署证书的主机不匹配而导致浏览器提示证书无效,但这并不影响使用。
需要手工生成证书的情况有:
- 找不到可用的证书
- 需要配置双向SSL,但缺少客户端证书
- 需要对证书作特别的定制
首先,无论是在Linux下还是在Windows下的Cygwin中,进行下面的操作前都须确认已安装OpenSSL软件包。
1. 创建根证书密钥文件(自己做CA)root.key:
openssl genrsa -des3 -out root.key
输出内容为:
[lenin@archer ~]$ 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
输出内容为:
[lenin@archer ~]$ 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.req -out root.crt
输出内容为:
[lenin@archer ~]$ 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
输出内容为:
[lenin@archer ~]$ openssl genrsa -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
输出内容为:
[lenin@archer ~]$ openssl req -new -key server.key -out server.req
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 -CAcreateserial -in server.csr -out server.crt
输出内容为:
[lenin@archer ~]$ openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -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
输出内容为:
[lenin@archer ~]$ 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
输出内容为:
[lenin@archer ~]$ 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 -CAcreateserial -in client.csr -out client.crt
输出内容为:
[lenin@archer ~]$ openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -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
输出内容为:
[lenin@archer ~]$ 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: ← 确认密码
11. 保存生成的文件备用,其中server.crt和server.key是配置单向SSL时需要使用的证书文件,client.crt是配置双向SSL时需要使用的证书文件,client.pfx是配置双向SSL时需要客户端安装的证书文件
.crt文件和.key可以合到一个文件里面,把2个文件合成了一个.pem文件(直接拷贝过去就行了)
相关推荐
linux下,私有ssl证书生成器,通过提示的方式,自动根据域名生成私有ssl证书,包括crt,key
这里说下Linux 系统怎么通过openssl命令生成 证书。 首先执行如下命令生成一个key
下载该证书,执行脚本,会生成证书文件。亲测有效
用openssl签发ssl x.509证书 建立根证书: 制做服务器端的证书并用ca签名: 生成crt格式 生成cer格式
linux下的ssl客户端和服务器端源码,包含了自己生成的证书和私钥。
本教程探讨了LAMP环境的额外设置,比如在Apache上创建虚拟主机、生成SSL证书文件及密钥、针对HTTP事务启用安全SSL协议,以及使用ApacheCGI网关,那样你就可以在自己的网站上运行Perl脚本或Bash脚本。这个话题使用一...
Linux操作系统,生成SSL加密证书,部署验证。Nginx中间件部署SSL加密证书。
通过shell脚本生成CA根证书,并且通过CA根证书自签服务器、客户端等证书; 自签后可以实现局域网内https证书信任。该证书可以实现V3(SAN)证书扩展名,解决谷歌浏览(Google Chrome)提示没有主题备用名称的问题。
这是一个Windows / Linux / Mac应用程序,可生成包括根CA证书在内的自签名SSL / TLS证书。 文件创建 选项#1-1证书: 选项#2-2个证书: 为什么要使用生成证书? 使用该程序只需1分钟,而输入和调整所有命令和...
生成证书:进入要生成证书的目录cd /usr/local/nginx/conf 使用openssl创建创建服务器私钥,输入相应提示的信息 代码如下:openssl genrsa -des3 -out server.key 1024 创建证书签名请求(Certificate Signing ...
在apache2服务器上配置SSL证书-Ubuntu 18.04 本教程是为已经拥有证书并需要在服务器上插入证书并将其配置为可在Apache2服务器上工作的人员制作的。 如果您没有证书,并且想生成免费的自签名证书,建议您遵循...
Linux Nginx 配置SSL访问实例详解 生成证书 可以通过以下步骤生成一个简单的证书: 首先,进入你想创建证书和私钥的目录,例如: $ cd /usr/local/nginx/conf 创建服务器私钥,命令会让你输入一个口令: $ ...
OMGWTFSSL-自签名SSL证书生成器 “我们应该尝试寻找omgwtfssl的替代品,该替代品目前用于生成自签名证书。该名称不恰当且不专业。” 关于 每次需要自签名证书时都会厌倦谷歌搜索吗? OMGWTFSSL是基于alpine linux的...
修改PFX证书使用时间,临时使用时间,延长SSL证书时间
为您的域/ IP生成100年的自签名ssl证书。 已要求 Linux 安装 npm install ssl-self-signed 例子 var sss = require ( 'ssl-self-signed' ) ; // auto generate CA sss ( { output : __dirname , commonName : '...
得用openssl生成私钥和证书文件。在socket编程时,加入ssl相关功能,达到工业级安全强度。
适用于Mac和Linux的Python设置,无需其他操作 数据库 安装Postgres版本12和postgresql-server-dev-12: sudo apt-get install postgresql-12 postgresql-server-dev-12 为Postgres创建用户和数据库 sudo su - ...
由于生成的证书是jks格式,nginx不能直接用,需要要转成PEM格式,这要用到jks2pfx工具进行转换。 jks2pfx的命令格式:JKS2PFX.bat keystore password alias exportname keystore:KeyStore文件绝对路径 将jks文件...
提供安全便捷的SSL证书申请和管理 AES256位私钥加密存储,守护您的资产和品牌声誉。 全新 2.0 正式上线 全新UI,支持梦幻蓝/暗黑模式; 重新设计功能菜单,操作更友好; 支持恢复密钥,解决密码忘记问题; ...