Redhat 中 powershell 的 New-SelfSignedCertificate 的等效命令是什么?

问题描述 投票:0回答:1

我需要创建一个证书并在我的计算机和 Azure 应用程序注册中使用它,以允许我的计算机通过 Azure Active Directory 进行身份验证,以便访问 azure KeyVault 中的机密。

当我使用Windows时,我通常这样做:

New-SelfSignedCertificate -Subject "CN=MyCertificate" -CertStoreLocation "Cert:\LocalMachine\My" -KeyExportPolicy Exportable -KeySpec Signature

但是现在当我想将我的应用程序移植到 Redhdat Linux 时,我很困惑如何做到这一点以及证书的存储位置。

是否有特定的命令或库可以做到这一点?

.net azure-active-directory redhat
1个回答
0
投票

要在 Red Hat Linux 上创建自签名证书以与 Azure Active Directory 和 Azure Key Vault 一起使用,您可以使用 OpenSSL,这是一种广泛使用的 SSL/TLS 证书管理工具。 使用 OpenSSL 生成 2048 位 RSA 私钥:

openssl genrsa -out mykey.key 2048

enter image description here

创建证书签名请求(CSR),然后生成自签名证书:

 openssl req -new -key mykey.key -out mycsr.csr -subj "/CN=MyCertificate"
openssl x509 -req -days 365 -in mycsr.csr -signkey mykey.key -out mycert.crt

enter image description here

这将生成一个名为

mycert.crt
的一年有效证书。 Azure 需要 PKCS#12(
.pfx
.p12
)格式的证书。结合您的证书和密钥:

openssl pkcs12 -export -out 证书.pfx -inkey mykey.key -in mycert.crt enter image description here

设置您的密码并记住您为此文件设置的密码。 将您的

.pfx
文件上传到 Azure: 有两种方法-

通过 Azure 门户: 在应用程序注册中的“证书和机密”下,上传

certificate.pfx
enter image description here 通过 Azure CLI: 使用 Azure CLI 上传:

az ad app credential reset --id <your-app-id> --cert @certificate.pfx --append

Linux系统没有像Windows那样有统一的证书存储。将您的证书和密钥存储在安全目录中,通常:

  • 证书:

    /etc/ssl/certs

  • 私钥:

    /etc/ssl/private

enter image description here 为私钥设置适当的权限:

sudo chown root:root mykey.key
sudo chmod 600 mykey.key

在您的应用程序中,根据 Azure 身份验证所需引用证书和密钥的路径。

参考文档:

使用 openssl 生成自签名证书

生成 Redhat 自签名证书

MS 文档

© www.soinside.com 2019 - 2024. All rights reserved.