前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >12.19 生成ssl密钥对

12.19 生成ssl密钥对

作者头像
运维小白
发布2018-02-06 16:01:05
1.4K0
发布2018-02-06 16:01:05
举报
文章被收录于专栏:运维小白运维小白

生成ssl密钥对目录概要

  • cd /usr/local/nginx/conf
  • openssl genrsa -des3 -out tmp.key 2048//key文件为私钥
  • openssl rsa -in tmp.key -out aminglinux.key //转换key,取消密码
  • rm -f tmp.key
  • openssl req -new -key aminglinux.key -out aminglinux.csr//生成证书请求文件,需要拿这个文件和私钥一起生产公钥文件
  • openssl x509 -req -days 365 -in aminglinux.csr -signkey aminglinux.key -out aminglinux.crt 这里的aminglinux.crt为公钥

生成ssl密钥对

在自己的虚拟机生成ssl 需要用到openssl工具

  • 在虚拟上颁发一套证书,生成ssl
  1. 首先得有一个openssl工具
  2. 切换到/usr/local/nginx/conf/目录下
[root@hf-01 ~]# cd /usr/local/nginx/conf/
[root@hf-01 conf]# 
  1. 若是没有openssl工具,可以安装下
  2. 查看openssl工具是由哪个安装包安装的
[root@hf-01 conf]# rpm -qf `which openssl`
openssl-1.0.2k-8.el7.x86_64
[root@hf-01 conf]# 
  1. 生成一个私钥,命令openssl genrsa -des3 -out tmp.key 2048
[root@hf-01 conf]# openssl genrsa -des3 -out tmp.key 2048
Generating RSA private key, 2048 bit long modulus
.......+++
......................................................................+++
e is 65537 (0x10001)
Enter pass phrase for tmp.key:        //输入密码
Verifying - Enter pass phrase for tmp.key:        //再次输入密码
[root@hf-01 conf]# 
  • openssl genrsa -des3 -out tmp.key 2048
    • genrsa ,表示生成rsa的私钥
    • 2048 ,2048长度
    • 名字为 tmp.key
  • 生成这个秘钥必须要有密码
  1. 在生成这个秘钥后比较麻烦,在nginx的配置文件里指定密码,每次访问浏览器,在https这个网址输入这个密码会很不方便,所以还需要去除这个密码
  2. 转换key,取消密码,命令 openssl rsa -in tmp.key -out gurui.key
  • -in 表示指定哪一个秘钥要被转换
  • -out 表示指定输出的
[root@hf-01 conf]# openssl rsa -in tmp.key -out gurui.key
Enter pass phrase for tmp.key:    //输入tmp.key的密码
writing RSA key
[root@hf-01 conf]# 
  1. 这时候tmp.key和gurui.key是属于同一个
  • tmp.key,有密码
  • gurui.key,没有密码
  1. 删除tmp.key
[root@hf-01 conf]# rm -f tmp.key
[root@hf-01 conf]# 
  1. 生成证书请求文件,需要拿这个请求文件和私钥一起生产公钥文件
[root@hf-01 conf]# openssl req -new -key gurui.key -out gurui.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) [XX]:cn              //国家,2个字母
State or Province Name (full name) []:JiangSu      //省或州
Locality Name (eg, city) [Default City]:YanCheng   //城市
Organization Name (eg, company) [Default Company Ltd]:han  //公司
Organizational Unit Name (eg, section) []:han   //组织
Common Name (eg, your name or your server’s hostname) []:hanfeng  //您的主机名
Email Address []:han1118feng@163.com   //邮箱
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:hanfeng  //设置密码
An optional company name []:  //一个可选的公司名称
用请求证书文件和私钥文件,生成一个公钥
[root@hf-01 conf]# 
  • 这里的信息可以不用填写,直接回车也行
  1. 因为这是自己给自己颁发的证书,可以随意填写,若是购买那些正式的证书,那证书的信息就需要填写相对应的信息
  2. 生成公钥,命令openssl x509 -req -days 365 -in gurui.csr -signkey gurui.key -out gurui.crt
[root@hf-01 conf]# openssl x509 -req -days 365 -in gurui.csr -signkey gurui.key -out gurui.crt
Signature ok
subject=/C=11/ST=BEIJING/L=BeiJing/O=hanfeng/OU=hanfeng/CN=hanfeng/emailAddress=han1118fem\x08
Getting Private key
[root@hf-01 conf]# 
  • -days 365 证书的日期是一年
  1. gui.crt是公钥,gurui.key是私钥
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 生成ssl密钥对目录概要
  • 生成ssl密钥对
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档