window和ubuntu自签证书

window下 以管理员身份 运行 Windows PowerShell

CN=192.168.0.100 (换成自己的IP或者域名)

O=(组织) OU=(组织单位)

Cert:\LocalMachine\My:证书存储位置

test_10:自定义证书名称 .AddYears(10): 证书过期时间 10 年

bash 复制代码
$cert = New-SelfSignedCertificate `
    -Subject "CN=192.168.0.100, O=test, OU=test" `
    -KeyAlgorithm RSA `
    -KeyLength 2048 `
    -NotAfter (Get-Date).AddYears(10) `
    -CertStoreLocation "Cert:\LocalMachine\My" `
    -FriendlyName "test_10"

"password": 证书密码 可以自己设置 ,后面导出和生成 使用

bash 复制代码
$password = ConvertTo-SecureString -String "password" -Force -AsPlainText

导出证书到D盘

bash 复制代码
Export-PfxCertificate `
    -Cert $cert `
    -FilePath "D:\test_10.pfx" `
    -Password $password

安装openssl

bash 复制代码
# 搜索 openssl	
winget search openssl

# 使用ID安装 openssl
winget install --id FireDaemon.OpenSSL

重启 power shell (以管理员身份)!!!

输入 openssl version 查看版本号,有输出说明安装没问题

bash 复制代码
password:上面自定义的证书密码

# 转换为 .key 私钥文件(无密码)
openssl pkcs12 -in "D:\test_10.pfx" -nocerts -out "D:\test_10.key" -nodes -passin pass:password

# 转换为 .crt 证书文件
openssl pkcs12 -in "D:\test_10.pfx" -clcerts -nokeys -out "D:\test_10.crt" -passin pass:password

证书生成完了,可以使用nginx配置 key 和 crt 记得编辑对自己的 server_name;

win+r 输入 certmgr.msc 查看当前计算机证书信息

bash 复制代码
# 查看证书信息
Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.FriendlyName -eq "test_10" } | Select-Object -Property Subject, DnsNameList, NotAfter

ubuntu 使用 openssl生成证书

bash 复制代码
# 生成私钥(RSA 2048位)
openssl genrsa -out server.key 2048

openssl rand -writerand /root/.rnd

# 生成证书签名请求(CSR)
openssl req -new -key server.key -out server.csr -subj "/CN=192.168.0.130/O=test/OU=test"

# 生成自签证书(有效期365天)
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt \
  -extfile <(printf "subjectAltName=DNS:192.168.0.130,DNS:localhost,IP:127.0.0.1")
相关推荐
未济2 天前
linux 配置环境变量
linux
傲世仙尊2 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
_艾伦 耶格尔.2 天前
进程间通信
linux
AI职业加油站2 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
Liuqy-052 天前
Linux IO编程——静态库、动态库
linux
此冬歌咏2 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
彧azz2 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅2 天前
linux(8) 软硬链接
linux·运维·服务器
AIgorithmGEEK2 天前
[Linux]线程三部曲(上):一个执行流的诞生——从操作系统一路拆到 pthread_create
linux·线程·pid