open ssl 生成自签名证书

本节向您展示如何使用' openssl '工具从命令行生成所有必要的文件。

  1. 使用实例生成2048位的RSA私钥,用于对流量进行解密。(这里的私钥没有使用加密,安全起见可以加密私钥)
bash 复制代码
$ sudo openssl genrsa -out /etc/grafana/grafana.key 2048

加密参数如下:

bash 复制代码
[root@localhost ~]# openssl genrsa --help
usage: genrsa [args] [numbits]
 -des            encrypt the generated key with DES in cbc mode
 -des3           encrypt the generated key with DES in ede cbc mode (168 bit key)
 -idea           encrypt the generated key with IDEA in cbc mode
 -seed
                 encrypt PEM output with cbc seed
 -aes128, -aes192, -aes256
                 encrypt PEM output with cbc aes
 -camellia128, -camellia192, -camellia256
                 encrypt PEM output with cbc camellia
 -out file       output the key to 'file
 -passout arg    output file pass phrase source
 -f4             use F4 (0x10001) for the E value
 -3              use 3 for the E value
 -engine e       use engine e, possibly a hardware device.
 -rand file:file:...
                 load the file (or the files in the directory) into
                 the random number generator
  1. 执行以下命令,使用上一步中的私钥生成证书。(csr这个里面包含公钥,所以这里需要私钥来生成对应的公钥)
bash 复制代码
$ sudo openssl req -new -key /etc/grafana/grafana.key -out /etc/grafana/grafana.csr

当提示时,回答问题,其中可能包括您的完全合格域名,电子邮件地址,国家代码等。下面的示例与您将看到的提示类似。

bash 复制代码
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]:US
State or Province Name (full name) [Some-State]:Virginia
Locality Name (eg, city) []:Richmond
Organization Name (eg, company) [Internet Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:subdomain.mysite.com
Email Address []:me@mysite.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
  1. 使用私钥自签名证书,证书有效期为365天。(颁发证书)
bash 复制代码
sudo openssl x509 -req -days 365 -in /etc/grafana/grafana.csr -signkey /etc/grafana/grafana.key -out /etc/grafana/grafana.crt
  1. 执行如下命令为文件设置相应的权限:
bash 复制代码
sudo chown grafana:grafana /etc/grafana/grafana.crt
sudo chown grafana:grafana /etc/grafana/grafana.key
sudo chmod 400 /etc/grafana/grafana.key /etc/grafana/grafana.crt
相关推荐
llilian_164 小时前
便携式相位测量模块应用方案的核心优势
网络·功能测试·单片机
无足鸟ICT4 小时前
【RHCA+】$[]
linux·运维·服务器
运维技术小记4 小时前
国产化环境配置 VNC 远程桌面:麒麟 V10 实战
linux·运维·服务器
QH139292318804 小时前
# R&S ZNB43 ZNA43 ZNA67矢量网络分析仪
开发语言·网络·php
栋***t4 小时前
2026年不止防作弊,麦塔在线培训系统培训与考试安全的体系化设计
网络·安全
xiaoye-duck5 小时前
《Linux系统编程》Linux 系统多线程(八): C++ 高并发线程池全链路深度解析与从零手撕实现
linux·c++·线程池
寒水馨5 小时前
Linux下载、安装protobuf-v35.1(附安装包protoc-35.1-linux-x86_64.zip)
linux·运维·服务器·google·序列化·protobuf·protoc
宁风NF6 小时前
JavaScript:网络请求与前端通信
开发语言·前端·javascript·网络·学习·ecmascript
王琦03186 小时前
Linux的文件管理
linux·运维·服务器
Android系统攻城狮6 小时前
Linux PipeWire深度解析之pw_stream_new调用流程与实战(四十二)
linux·运维·服务器·音频进阶·pipewire音频进阶