发布于2026-08-21 阅读(0)
扫一扫,手机访问
OpenSSL是一个强大的加密工具,可以在Linux系统中用于生成证书、密钥、签名等

#!/bin/bash
# 设置变量
domain="example.com"
email="admin@example.com"
output_dir="/etc/ssl/certs"
private_key_file="${output_dir}/${domain}.key"
certificate_file="${output_dir}/${domain}.crt"
certificate_signing_request_file="${output_dir}/${domain}.csr"
# 创建输出目录
mkdir -p "${output_dir}"
# 生成私钥
openssl genrsa -out "${private_key_file}" 2048
# 生成证书签名请求
openssl req -new -key "${private_key_file}" -out "${certificate_signing_request_file}" -subj "/C=US/ST=YourState/L=YourCity/O=YourOrganization/CN=${domain}" -addext "emailAddress=${email}"
# 生成自签名证书
openssl x509 -req -days 365 -in "${certificate_signing_request_file}" -signkey "${private_key_file}" -out "${certificate_file}"
# 输出证书信息
echo "Certificate for ${domain} has been generated."
echo "Private key file: ${private_key_file}"
echo "Certificate file: ${certificate_file}"把这个脚本存成generate_ssl.sh,接着在终端里运行chmod +x generate_ssl.sh,让它能够被执行。随后,运行./generate_ssl.sh来生成证书和密钥。
需注意,此脚本仅作演示之用,在实际生产环境里,或许需要更为复杂的配置。于生产环境中,您很可能得借助Let’s Encrypt或其他证书颁发机构来获取免费证书。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
4
5
6
7
8
9