使用Let's Encrypt手動創建https證書


Let’s Encrypt是一個開源免費的SSL證書項目,是由 Mozilla、思科、Akamai、IdenTrust 和 EFF 等組織發起的,現由Linux基金會托管。

這篇博文分享的是使用letsencrypt成功在Linux Ubuntu上生成ssl證書的操作步驟。

1、安裝letsencrypt

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto --help

2、生成私鑰

openssl genrsa 4096 > x.cnblogs.com.key

3、生成CSR(Certificate Signing Reqeust)

openssl req -new -sha256 \
    -key x.cnblogs.com.key \
    -subj "/C=CN/ST=省份/L=城市/O=部門/OU=公司/CN=x.cnblogs.com" \
    -reqexts SAN \
    -outform der \
    -config <(cat /etc/ssl/openssl.cnf \
        <(printf "[SAN]\nsubjectAltName=DNS:x.cnblogs.com")) \
    -out x.cnblogs.com.csr

4、向letsencrypt服務器發起獲取證書的請求

./letsencrypt-auto certonly \
    --authenticator manual \
    --server https://acme-v01.api.letsencrypt.org/directory --text \
    --email x@cnblogs.com \
    --csr x.cnblogs.com.csr

在出現”Press ENTER to continue“時,不要動,進行下一步操作。

5、驗證證書對應域名的所有權
如果對應的站點已經在運行,可以創建這樣的URL:/.well-known/acme-challenge/xxx,以便letsencrypt服務器可以訪問這個URL進行驗證。
如果沒有對應的站點,可以用python臨時運行Web站點進行驗證,參考下面的提示:

Make sure your web server displays the following content at
http://x.cnblogs.com/.well-known/acme-challenge/xxx before continuing:

xxxxxx...

If you don't have HTTP server configured, you can run the following
command on the target server (as root):

mkdir -p /tmp/letsencrypt/public_html/.well-known/acme-challenge
cd /tmp/letsencrypt/public_html
printf "%s" xxxxxx... > .well-known/acme-challenge/xxx
# run only once per server:
$(command -v python2 || command -v python2.7 || command -v python2.6) -c \
"import BaseHTTPServer, SimpleHTTPServer; \
s = BaseHTTPServer.HTTPServer(('', 80), SimpleHTTPServer.SimpleHTTPRequestHandler); \
s.serve_forever()" 

6、回到第4步的操作窗口按回車鍵,如果證書成功創建,會出現下面的提示:

 - Congratulations! Your certificate and chain have been saved at ...

然后在當前文件夾中就會看到擴展名為.pem的證書文件。

0000_cert.pem
參考資料


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM