debian

OpenSSL在Debian上的证书管理怎么做

小樊
43
2025-08-20 11:57:42
栏目: 云计算

OpenSSL在Debian上的证书管理主要涉及安装、生成、查看及配置等操作,以下是关键步骤:

  1. 安装OpenSSL

    sudo apt update && sudo apt install openssl  
    
  2. 生成私钥

    openssl genpkey -algorithm RSA -out private.key -aes256  # 生成加密的RSA私钥  
    
  3. 创建证书签名请求(CSR)

    openssl req -new -key private.key -out certificate.csr  # 需填写国家、组织等信息  
    
  4. 生成自签名证书(测试用)

    openssl x509 -req -days 365 -in certificate.csr -signkey private.key -out certificate.crt  
    
  5. 查看证书信息

    openssl x509 -in certificate.crt -text -noout  
    
  6. 验证证书

    • 验证单个证书:
      openssl verify -CAfile ca.crt certificate.crt  # 需提供CA证书  
      
    • 验证证书链:
      openssl verify -CAfile ca-bundle.crt certificate.crt  
      
  7. 转换证书格式(如PKCS#12)

    openssl pkcs12 -export -in certificate.crt -inkey private.key -out certificate.p12 -name "MyCert"  
    
  8. 配置Web服务器(以Nginx为例)

    • 将证书和私钥复制到指定目录:
      sudo cp certificate.crt /etc/ssl/certs/  
      sudo cp private.key /etc/ssl/private/  
      
    • 编辑Nginx配置文件,指定证书路径:
      ssl_certificate /etc/ssl/certs/certificate.crt;  
      ssl_certificate_key /etc/ssl/private/private.key;  
      
    • 重启服务:
      sudo systemctl restart nginx  
      

说明:生产环境建议使用CA签发的证书,自签名证书仅适用于测试。私钥需妥善保管,避免泄露。[1,2,3,4,5,6,7,8,9,10,11]

0
看了该问题的人还看了