执行 sudo openssl req -x509 -days 3650 -nodes -newkey rsa:2048 -keyout logstash-remote.key -out logstash-remote.crt
命令后,openssl
会提示你输入一些信息来生成自签名证书。这些信息包括国家、州/省、市、组织、组织单位、通用名称(Common Name,通常是域名或 IP 地址)以及电子邮件地址。
以下是执行该命令后的典型提示和输入示例:
$ sudo openssl req -x509 -days 3650 -nodes -newkey rsa:2048 -keyout logstash-remote.key -out logstash-remote.crt
Generating a RSA private key
..................................................+++++
................................+++++
writing new private key to 'logstash-remote.key'
-----
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]:US
State or Province Name (full name) [Some-State]:California
Locality Name (eg, city) []:San Francisco
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Company
Organizational Unit Name (eg, section) []:IT Department
Common Name (e.g. server FQDN or YOUR name) []:example.com
Email Address []:admin@example.com
各个字段的解释
- Country Name (2 letter code): 国家代码,两个字母。例如,美国是
US
,中国是CN
。 - State or Province Name (full name): 州或省的全名。例如,加利福尼亚州是
California
。 - Locality Name (eg, city): 城市名称。例如,旧金山是
San Francisco
。 - Organization Name (eg, company): 组织名称或公司名称。例如,
My Company
。 - Organizational Unit Name (eg, section): 组织单位名称,例如部门名称。可以留空。
- Common Name (e.g. server FQDN or YOUR name): 通用名称,通常是服务器的完全限定域名(FQDN)或 IP 地址。例如,
example.com
。 - Email Address: 电子邮件地址。可以留空。
示例输入
假设你要为域名 example.com
生成一个自签名证书,你可以按如下方式输入:
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:California
Locality Name (eg, city) []:San Francisco
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Company
Organizational Unit Name (eg, section) []:IT Department
Common Name (e.g. server FQDN or YOUR name) []:example.com
Email Address []:admin@example.com
注意事项
- Common Name (CN): 这个字段非常重要,通常应该是你服务器的域名或 IP 地址。如果你使用的是域名,请确保它与你访问服务器时使用的域名一致。
- Email Address: 这个字段可以留空,但填写一个有效的电子邮件地址有助于联系证书的所有者。
完成这些输入后,openssl
会生成两个文件:
logstash-remote.key
: 私钥文件。logstash-remote.crt
: 自签名证书文件。
这两个文件可以用于配置你的服务(例如 Logstash)以启用 SSL/TLS 加密。