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 小时前
【C#】用 DevExpress 创建带“下拉子表”的参数表格视图
linux·windows·c#
咖喱年糕1 小时前
【Linux】系统指令与开发全栈(vim、ssh、gcc)
linux·ssh·vim·gcc
时光飞逝的日子3 小时前
Ubuntu搭建NFS服务器的方法
ubuntu·nfs
charlie1145141914 小时前
Linux内核深入学习(4)——内核常见的数据结构2——红黑树
linux·数据结构·学习·红黑树
chen.@-@4 小时前
Linux 常用命令
linux
不愧是你呀4 小时前
Linux利用多线程和线程同步实现一个简单的聊天服务器
linux·服务器
liulangrenaaa4 小时前
C语言实现android/linux按键模拟
android·linux·c语言
WuYiCheng6665 小时前
CentOS高手之路:从进阶实战到企业级优化
linux·运维·centos
猴子请来的逗比4895 小时前
mysql的安装方式
linux·数据库·学习·mysql
非自律懒癌患者6 小时前
ubuntu 20.04 ping baidu.coom可以通,ping www.baidu.com不通 【DNS出现问题】解决方案
linux·tcp/ip·ubuntu