ubuntu 使用openssl制作一个自签名证书

我们需要为浏览器创建自己的根CA证书来信任自签名证书。因此,让我们首先创建根CA证书

创建根CA证书

  1. 创建文件夹
bash 复制代码
mkdir openssl && cd openssl
  1. 执行以下openssl命令,生成 rootCA.key 以及 rootCA.crt. 用你的域名或者ip地址替换demo.mlopshub.com
bash 复制代码
openssl req -x509 \
            -sha256 -days 356 \
            -nodes \
            -newkey rsa:2048 \
            -subj "/CN=demo.mlopshub.com/C=US/L=San Fransisco" \
            -keyout rootCA.key -out rootCA.crt 

如果上述命令提示Can't load /home/username/.rnd into RNG,则需要你手动创建这个文件

生成自签名证书

  1. 生成server的私有key
bash 复制代码
openssl genrsa -out server.key 2048
  1. 创建证书签名请求配置
    根据实际情况替换域名以及IP
bash 复制代码
cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C = US
ST = California
L = San Fransisco
O = MLopsHub
OU = MlopsHub Dev
CN = demo.mlopshub.com

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = demo.mlopshub.com
DNS.2 = www.demo.mlopshub.com
IP.1 = 192.168.1.5
IP.2 = 192.168.1.6

EOF
  1. 使用服务器私钥生成证书签名请求(CSR)
bash 复制代码
openssl req -new -key server.key -out server.csr -config csr.conf
  1. 创建一个外部文件
    根据实际情况替换域名以及IP
bash 复制代码
cat > cert.conf <<EOF

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = demo.mlopshub.com

EOF
  1. 使用自签名CA生成SSL证书
bash 复制代码
openssl x509 -req \
    -in server.csr \
    -CA rootCA.crt -CAkey rootCA.key \
    -CAcreateserial -out server.crt \
    -days 365 \
    -sha256 -extfile cert.conf

server.crt 以及server.key就是我们在ingress创建secret或者nginx里用到的配置项

相关推荐
学嵌入式的小杨同学1 小时前
从零打造 Linux 终端 MP3 播放器!用 C 语言实现音乐自由
linux·c语言·开发语言·前端·vscode·ci/cd·vim
EverydayJoy^v^1 小时前
RH134学习进程——十二.运行容器(1)
linux·运维·容器
syseptember1 小时前
Linux网络基础
linux·网络·arm开发
zl_dfq1 小时前
Linux 之 【多线程】(线程的概念、Linux中的线程、页表)
linux
郝亚军2 小时前
如何在Ubuntu和win10/11之间通过samba访问对方的文件
linux·服务器·ubuntu
曦云沐3 小时前
【避坑指南】Ubuntu更新报错“Repository is not signed”的快速修复
linux·ubuntu·docker
带土13 小时前
10. .out文件
linux
STCNXPARM4 小时前
Linux camera之V4L2子系统详解
android·linux·camera·v4l2架构
yueyuexiaokeai14 小时前
linux kernel常用函数整理
linux·c语言
郝亚军6 小时前
ubuntu-18.04.6-desktop-amd64安装步骤
linux·运维·ubuntu