Linux 產生自簽憑證

安裝 openssl 套件:
    
sudo apt update && sudo apt install openssl -y
    

產生 RSA 私鑰
    
openssl genrsa -out server.key 2048
    

範例輸出:
    
openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
............................................................+++++
...+++++
e is 65537 (0x010001)
    

使用私鑰生成自簽名憑證:
    
openssl req -new -x509 -key server.key -out server.crt -days 365
    

依照提示輸入基本資訊:
    
openssl req -new -x509 -key server.key -out server.crt -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taipei
Locality Name (eg, city) []:Taipei City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ruyut
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []: Ruyut
Email Address []:service@uyut.com
    

成功產生 server.crt 憑證檔案:
    
ls
server.crt  server.key
    

留言