[Ubuntu] 使用 OpenSSL 產生憑證

Ubuntu 18.04

在 Ubuntu 下使用 openssl 產生憑證方法如下:

1. 使用 RSA 演算法產生 2048 bit 長度私鑰 (ca.key)

$ openssl genrsa -out ca.key 2048

Generating RSA private key, 2048 bit long modulus
............+++
..................+++
e is 65537 (0x010001)

2. 簽發憑證 (ca.crt)

$ openssl req -new -x509 -key ca.key -out ca.crt

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]:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]:LADSAI
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:ladsai.com
Email Address []:ray@ladsai.com
  1. 所有資料都要填英文 (ASCII 字集) 。 X.509 憑證只接受 英文 ASCII 字集的字。
  2. Country Name 一定要是大寫的雙字母國碼,臺灣是 TW ,臺灣以外的地方,請參考 ISO-3166 的標準雙字母國碼。
  3. State Name 是國名或省名,不可以填國碼。臺灣填 Taiwan 即可。
  4. Locality Name 是地名,填所在地縣市名即可。
  5. Organization Name 是組織單位名稱,填公司行號,或學校 局處的名稱。
  6. Organizational Unit Name 是部門名稱,填公司部門名稱 ,或學校局處的單位名稱。
  7. Common Name 是憑證的名稱。若是最上層憑證機構,請填上 前面填的組織單位名稱。若是伺服器憑證,請填上伺服器的全名 (www.abc.com) 。若是 E-mail 憑證,請填上妳的 E-mail 。
  8. E-mail Address 是申請單位的連絡信箱,請填上你的聯絡 用 E-mail。
3. 使用 RSA 演算法產生 2048 bit 長度私鑰 (client.key)

$ openssl genrsa -out client.key 2048

Generating RSA private key, 2048 bit long modulus
..........................+++
...............+++
e is 65537 (0x010001)
4. 產生憑證簽署要求 Certificate Signing Request (client.csr)

$ openssl req -new -key client.key -out client.csr

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]:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ladsai
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:ladsai.com
Email Address []:ray@ladsai.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
  1. 所有資料都要填英文 (ASCII 字集) 。 X.509 憑證只接受 英文 ASCII 字集的字。
  2. Country Name 一定要是大寫的雙字母國碼,臺灣是 TW ,臺灣以外的地方,請參考 ISO-3166 的標準雙字母國碼。
  3. State Name 是國名或省名,不可以填國碼。臺灣填 Taiwan 即可。
  4. Locality Name 是地名,填所在地縣市名即可。
  5. Organization Name 是組織單位名稱,填公司行號,或學校 局處的名稱。
  6. Organizational Unit Name 是部門名稱,填公司部門名稱 ,或學校局處的單位名稱。
  7. Common Name 是憑證的名稱。若是最上層憑證機構,請填上 前面填的組織單位名稱。若是伺服器憑證,請填上伺服器的全名 (www.abc.com) 。若是 E-mail 憑證,請填上妳的 E-mail 。
  8. E-mail Address 是申請單位的連絡信箱,請填上你的聯絡 用 E-mail。
  9. A challenge password 是CSR的密碼。不過CSR不用設密碼,所以不填。
  10. An optional company name 是憑證代辦公司的名稱,也不用填。
5. 簽發憑證 (client.crt)

$ openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt

Signature ok
subject=C = TW, ST = Taiwan, L = Taipei, O = LADSAI, OU = IT, CN = LADSAI.COM, emailAddress = ray@ladsai.com
Getting CA Private Key

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *