• 一条命令创建自签名证书?



    只需要一条命令,就可以创建1个自签名证书,这个自签名证书,可以用在nginx中,作为server端证书:

     

    openssl req -x509 \
            -newkey \
            rsa:4096 \
            -nodes \
            -keyout server.key \
            -out server.crt \
            -sha256 \
            -days 3650 \
            -subj "/C=CN/ST=Beijing/L=Beijing/O=Alididi/OU=Ops/CN=www.example.com"

    参数说明:

    • -days 3650,证书有效期
    • -subj为使用者信息.
    • -nodes:为不需要密码的证书。

     

    执行命令后:

     

    [root@centos7 nginx]# openssl req -x509 \
    >         -newkey \
    >         rsa:4096 \
    >         -nodes \
    >         -keyout server.key \
    >         -out server.crt \
    >         -sha256 \
    >         -days 3650 \
    >         -subj "/C=CN/ST=Beijing/L=Beijing/O=Alididi/OU=Ops/CN=www.example.com"
    Generating a 4096 bit RSA private key
    .......++
    ........................................................++
    writing new private key to 'server.key'
    -----
    [root@centos7 nginx]# ls -l
    total 8
    -rw-r--r--. 1 root root 2025 Aug 25 01:50 server.crt
    -rw-r--r--. 1 root root 3272 Aug 25 01:50 server.key
    [root@centos7 nginx]# 

     

    这样,就生成了证书和key.

     

    增加多个DNS(使用者可选名称)

     

    使用subjectAltName中,使用备用的DNS的名字

    -extensions san \
            -config <(echo '[req]'; echo 'distinguished_name=req';
            echo '[san]'; echo 'subjectAltName=DNS:example.com,DNS:example.net')

     

    openssl req -x509 \
            -newkey \
            rsa:4096 \
            -nodes \
            -keyout server.key \
            -out server.crt \
            -sha256 \
            -days 3650 \
            -subj "/C=CN/ST=Beijing/L=Beijing/O=Alididi/OU=Ops/CN=www.example.com" \
            -extensions san \
            -config <(echo '[req]'; echo 'distinguished_name=req';
            echo '[san]'; echo 'subjectAltName=DNS:example.com,DNS:example.net')

     

    执行的过程

    [root@centos7 nginx]# openssl req -x509 \
    >         -newkey \
    >         rsa:4096 \
    >         -nodes \
    >         -keyout server.key \
    >         -out server.crt \
    >         -sha256 \
    >         -days 3650 \
    >         -subj "/C=CN/ST=Beijing/L=Beijing/O=Alididi/OU=Ops/CN=www.example.com" \
    >         -extensions san \
    >         -config <(echo '[req]'; echo 'distinguished_name=req';
    >         echo '[san]'; echo 'subjectAltName=DNS:example.com,DNS:example.net')
    Generating a 4096 bit RSA private key
    ..............................................................................++
    .....................................++
    writing new private key to 'server.key'
    -----
    [root@centos7 nginx]# ls
    server.crt  server.key
    [root@centos7 nginx]# ls -l
    total 8
    -rw-r--r--. 1 root root 1968 Aug 25 02:11 server.crt
    -rw-r--r--. 1 root root 3272 Aug 25 02:11 server.key
    [root@centos7 nginx]# 

     

    OK,这个时候,已经生成了有多个备选名字的证书。

  • 相关阅读:
    hibernate>悲观锁和乐观锁 小强斋
    hibernate>查询语言hql 小强斋
    hibernate>查询语言hql 小强斋
    hibernate>Collection映射 小强斋
    【java&&jni】jni入门篇
    【C++ Primer】第十三章 类继承
    【android&&jni&&NDk】详细介绍每一步,让你轻松掌握android JNI NDk
    【android】错误集锦及解决办法
    【Android】入门级连接网络示例: 网页浏览和播放网络MP3
    【python】入门第一篇
  • 原文地址:https://www.cnblogs.com/chuanzhang053/p/16624147.html
Copyright © 2020-2023  润新知