157 lines
8.1 KiB
Markdown
157 lines
8.1 KiB
Markdown
在本教程中,我们将向您演示如何在 CentOS 7 和 6 中生成 CSR。 您可以直接从服务器生成 CSR。
|
||
|
||
只需按照以下步骤操作即可:
|
||
|
||
## 第 1 步:使用安全外壳 (SSH) 登录服务器
|
||
|
||
### 第二步:创建私钥和 CSR 文件
|
||
|
||
在提示符下键入以下命令
|
||
|
||
`openssl req -new -newkey rsa:2048 -nodes -keyout mydomain.key -out mydomain.csr`
|
||
|
||
确保将_mydomain _替换为您的实际域名。 例如,如果域名是_example.com_,则必须输入_example.key_和_example.csr_。
|
||
|
||
### 第 3 步:向 CA 提交有关贵组织的详细信息
|
||
|
||
请按照下面的示例操作:
|
||
|
||
* **国名 **– 使用贵组织正式注册所在国家的双字母缩写。 例如,如果在美国注册,请输入**US**,如果在英国注册,请输入**UK**
|
||
* **州或 **省 – 输入贵组织注册所在州或省的全称
|
||
* **城市或地区 **-请输入贵机构所在城市的全称
|
||
* **组织名称 **– 如果您申请的是商业验证或扩展验证证书,请输入您公司的法定名称。 如果您要申请域名验证证书,请使用您的全名。
|
||
* **组织单位名称 **– 如果适用,您可以在此输入您的 DBA(Doing as business)名称。 或者,也可以指定管理 SSL 证书的部门。 例如,**信息技术**或**网络管理**
|
||
* **通用名称 **– 输入要保护的完全合格域名 (FQDN)。 (例如:ssldragon.com)\
|
||
注意:如果申请通配符 SSL 证书,必须在域名前添加星号。例如,\*.ssldragon.com。请勿在此字段中包含 “https “或任何其他字符。
|
||
* **电子邮件地址 **– 输入有效的电子邮件地址,作为域名的联系方式
|
||
* **密码 **– 此栏为可选项。 您可以使用密码进一步确保 SSL 证书的安全,也可以留空此栏。
|
||
|
||
您的 CSR 代码已准备就绪! 您可以使用**ls**命令在工作目录中找到它。 两个新文件是**yourdomainname.csr** 和**yourdomainame.key**_。_
|
||
|
||
_.csr_文件包含证书签名请求,您在订购 SSL 证书时需要将该请求提交给证书颁发机构。
|
||
|
||
CA 验证 CSR 并签发 SSL 证书后,就可以继续执行[CentOS SSL 安装说明](https://www.ssldragon.com/zh/how-to/install-ssl-certificate/centos/)。
|
||
|
||
https://www.ssldragon.com/zh/how-to/generate-csr/centos/
|
||
|
||
---
|
||
|
||
|
||
1.先创建个文件夹,然后进入这个文件夹执行命令:
|
||
mkdir ssl
|
||
cd ssl
|
||
2.执行命令:
|
||
openssl req -nodes -newkey rsa:2048 -keyout myserver.key -out server.csr
|
||
执行完会出现一些要输入的信息:
|
||
|
||
Country Name (2 letter code) [AU]: CN (国家代码)
|
||
State or Province Name (full name) [Some-State]: BJ (省)
|
||
Locality Name (eg, city) []: BJ (城市)
|
||
Organization Name (eg, company) [Internet Widgits Pty Ltd]: iHost (企业/组织)
|
||
Organizational Unit Name (eg, section) []: IT (部门)
|
||
Common Name (eg, YOUR name) []: ibaohost.com (域名/请正确填写)
|
||
Email Address []: (可直接回车)
|
||
Please enter the following 'extra' attributes to be sent with your certificate request
|
||
|
||
A challenge password []: (直接回车)
|
||
An optional company name []: (直接回车)
|
||
Use the name of the web-server as Common Name (CN). If the domain name (Common Name) is mydomain.com append the domain to the hostname (use the fully qualified domain name).
|
||
|
||
其中的Email Address 和 A challenge password 可以留空,不必填写,直接回车。以上需要填写的内容,如果你不清楚应该怎么填写,除了域名,其他的你可以按照上面的内容填写。
|
||
|
||
3.执行完 命令后 ,输入命令: ls
|
||
可以看到生成的key和csr文件
|
||
|
||
|
||
|
||
|
||
执行这些需要在服务器上装了ssl。
|
||
下面还有一种方法:简便的三条命令:
|
||
yum install openssl 安装
|
||
|
||
openssl genrsa -out wantsong.life.key 2048 生成key文件 2048位
|
||
|
||
openssl req -new -key wantsong.life.key -out wantsong.life.csr
|
||
|
||
|
||
|
||
|
||
|
||
openssl req -new -newkey rsa:2048 -nodes -keyout wantsong.life.key -out wantsong.life.csr
|
||
该命令会创建一个 2048 位加密的新私钥,同时生成一个新的 CSR。
|
||
|
||
|
||
|
||
• 系统将提示您输入有关您的组织的一些信息,例如国家/地区代码、州/省、城市/地区、组织名称和常用名称(域名)。如果您不想提供某些信息,可以按 Enter 键将某些字段留空。
|
||
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]:CN
|
||
State or Province Name (full name) [Some-State]:California Locality Name (eg, city) []:San Francisco
|
||
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Example Company Ltd. Organizational Unit Name (eg, section) []:
|
||
Common Name (e.g. server FQDN or YOUR name) []:example.com Email Address []:
|
||
• 提供所有必需的信息后,该工具将在您的当前目录中生成两个文件 - “example.com.key”和“example.com.csr”。前者是您的私钥,后者是您的 CSR。
|
||
|
||
Country Name (2 letter code) [XX]:CN
|
||
State or Province Name (full name) []:Shaanxi
|
||
Locality Name (eg, city) [Default City]:Xi'an
|
||
Organization Name (eg, company) [Default Company Ltd]:Wantsong EMC LLC
|
||
Organizational Unit Name (eg, section) []:SM
|
||
Common Name (eg, your name or your server's hostname) []:wantsong.life
|
||
Email Address []:wantsong@gmail.com
|
||
Please enter the following 'extra' attributes
|
||
to be sent with your certificate request
|
||
A challenge password []:jC!LW78j33
|
||
An optional company name []:Wantsong LLC
|
||
-----BEGIN CERTIFICATE REQUEST-----
|
||
MIIDEDCCAfgCAQAwgZIxCzAJBgNVBAYTAkNOMRAwDgYDVQQIDAdTaGFhbnhpMQ4w
|
||
DAYDVQQHDAVYaSdhbjEZMBcGA1UECgwQV2FudHNvbmcgRU1DIExMQzELMAkGA1UE
|
||
CwwCU00xFjAUBgNVBAMMDXdhbnRzb25nLmxpZmUxITAfBgkqhkiG9w0BCQEWEndh
|
||
bnRzb25nQGdtYWlsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
||
ANy+rgwpyv8/tzieUMDrkLQD9y+Pkvm7n5C2oQuAPT3byMxXF4B4Su0icCKAgUjh
|
||
qG631tVg8aqlG9Kw8E4VRAPUNg/OCBd/4NbmmSSRoYyDbYM14ZPrvKLvM8KmzTMM
|
||
F8ecqaHfTtMo8AKR21jtoSKc+NiSn7JMDHEbsQS+sMd0CwDvDTe1jE8f9yohStFg
|
||
ct61wH46zK5COWyhsFlNRxupH121B2DolKelGrweDz0Xnj/LZqgjk5yJsrgUS+XG
|
||
NjF5i7B9H1OVfilXwKseJhouOjvkzELlNNKPhDSkLHqfl6Q+LNi3d3RREK6Octo+
|
||
xTsdZVb5PYuZwwXWYprYh7sCAwEAAaA4MBkGCSqGSIb3DQEJBzEMDApqQyFMVzc4
|
||
ajMzMBsGCSqGSIb3DQEJAjEODAxXYW50c29uZyBMTEMwDQYJKoZIhvcNAQELBQAD
|
||
ggEBAD2YI1J/whCYlW1pQM97Aur+QPmWclVRobOjOjpvPpLJNA4dIKeoVVzg3xqW
|
||
Lq/pVaK4jUp5BvdnjVmXuBb7n6QRWo2q/tANd/bqItUfyBmuNSp91oR7883Mx9NS
|
||
sWmZjiEnWvgHIyqGkWvuBDaGSojqFG+5UkhIvjnKOnd8nNKIcLeyFzlBB/JcJOWP
|
||
JEH6UzAwRnZt03Xu702QFKjlE3Y7f6OvxjIaB48llRc8g7tDyEdvaiDPW68oNUTp
|
||
bw/5HRvLHnDIskP3BTYWwfo+2LsrFPfSdViaegbP1r6Nu/Ub+FFFwTcnSxNj+bgy
|
||
TA7Gq9hBknYJTW5+sanjYD5r+rQ=
|
||
-----END CERTIFICATE REQUEST-----
|
||
|
||
|
||
解释命令中使用的每个选项
|
||
现在让我们仔细看看 OpenSSL 命令中使用的每个选项: - req:这告诉 OpenSSL 创建一个新的 CSR。
|
||
• new - 这告诉 OpenSSL 我们想要生成一个新的 CSR,而不是使用现有的 CSR。
|
||
• newkey rsa:2048 - 这告诉 OpenSSL 创建一个具有 2048 位加密的新 RSA 私钥。
|
||
• nodes - 这告诉 OpenSSL 不要加密私钥。换句话说,它创建一个未加密(明文)的私钥。
|
||
• keyout example.com.key - 这指定您要保存私钥的位置。将“example.com”替换为您的实际域名。
|
||
• out example.com.csr - 这指定您要保存 CSR 的位置。再次,将“example.com”替换为您的实际域名。
|
||
要避免的常见错误
|
||
以下是使用 OpenSSL 生成 CSR 时应避免的一些常见错误 -
|
||
• 输入错误的组织信息可能会导致稍后申请 SSL/TLS 证书时出现错误。确保准确输入所有必填字段并在提交前仔细检查。
|
||
|
||
|
||
|
||
• 忘记包含或错误输入电子邮件地址可能会导致延迟接收有关 SSL/TLS 证书申请状态或到期日期的重要通知。
|
||
• 对私钥使用弱加密(少于 2048 位)可能会危及网站的安全性,并允许黑客窃取用户的敏感数据。
|
||
始终使用强加密以获得最大的安全性。
|
||
|
||
|
||
|
||
|
||
|
||
查找文件
|
||
ls -l wantsong.life.*
|
||
|
||
ls -l
|
||
|
||
|
||
创建CSR后,使用 cat 实用程序查看文件的内容,选择并复制它。
|
||
cat wantsong.life.csr
|