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.pemEnter 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
請在這一步設置一個密碼。我們將會在正式使用之前清除這個密碼。用戶只需要在后面的幾步中使用該密碼。