1.前提
检查是否已安装 openssl
$ which openssl
/usr/bin/openssl
2.建立CA授权中心
2.1.生成ca私钥(ca-prikey.pem)
初始化 OpenSSL 证书颁发机构(CA)的序列号文件
在生成证书时,ca.srl 的初始序列号需正确初始化(如 01),否则可能导致证书冲突
这会将 01 显示在屏幕上,并同时写入 ca.srl 文件
例如:echo 01 | tee -a output.txt 指的是将01追加到 output.txt 文件的末尾,而不是覆盖文件。
echo 01 | sudo tee ca.srl
在创建私钥的过程中,我们需要为 CA 密钥设置一个密码,我们需要牢记这个密码,并确保它的安全性。在新 CA 中,我们需要用这个密码来创建并对证书签名,密码:123456
openssl genrsa -des3 -out ca-prikey.pem
2.2.创建ca证书(ca-cert.pem)
将创建一个名为 ca-cert.pem 的文件,这也是我们的 CA 证书。我们之后也会用这个文件来验证连接的安全性。
openssl req -new -x509 -days 365 -key ca-prikey.pem -out ca-cert.pem
Enter pass phrase for ca-key.pem:
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]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:docker.example.com
Email Address []:
3.生成服务器的证书签名和密钥
3.1生成服务器私钥(server-prikey.pem)
命令跟生成ca私钥一样,密码:123456
请在这一步设置一个密码。我们将会在正式使用之前清除这个密码。用户只需要在后面的几步中使用该密码。