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")
相关推荐
NightReader23 分钟前
SSH Client推荐集
运维·ssh
小章UPUP42 分钟前
2025-2026 新FFmpeg GUI工具推荐
linux
探索宇宙真理.2 小时前
Nginx UI MCP接口绕过认证漏洞 | CVE-2026-33032复现&研究
运维·经验分享·网络安全·nginx-ui
llm大模型算法工程师weng2 小时前
负载均衡做什么?nginx是什么
运维·开发语言·nginx·负载均衡
byoass2 小时前
企业云盘私有化部署:存储架构设计与安全运维全流程实战
运维·网络·安全·云计算
fTiN CAPA2 小时前
服务器无故nginx异常关闭之kauditd0 kswapd0挖矿病毒 CPU占用200% 内存耗尽
运维·服务器·nginx
北山有鸟3 小时前
相机的水平消隐与垂直消隐
linux·驱动开发·相机
还不秃顶的计科生3 小时前
多模态模型下载
java·linux·前端
无忧.芙桃3 小时前
进程控制之进程等待
linux·运维·服务器
云栖梦泽3 小时前
Linux内核与驱动:13.从设备树到Platform平台总线
linux·运维·c++·嵌入式硬件