制作本地ssl证书

1
2
3
4
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

证书申请安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# acme 安装
wget -O - https://get.acme.sh | sh
wget https://gitee.com/neilpang/acme.sh/raw/master/acme.sh # 中国大陆使用
. .bashrc
# 自动升级
acme.sh --upgrade --auto-upgrade
# 测试
acme.sh --issue --server https://acme-staging-v02.api.letsencrypt.org/directory --test -d example.com -w /work/www/webpage/ --keylength ec-256

# 安装正式证书
acme.sh --set-default-ca --server letsencrypt
acme.sh --issue -d example.com -w /work/www/webpage/ --keylength ec-256 --force
# dns 方式安装 不需要ip和网站, 这里不同域名服务器的api不一样,参考
# https://github.com/acmesh-official/acme.sh/wiki/dnsapi
export Namesilo_Key="Namesilo_Key"
acme.sh --issue --dns dns_namesilo -d example.com -d *.example.com --dnssleep 1800
# 证书安装后秘钥不是可读的,更改权限让其他用户可读
chmod +r /path/to/key
# 官方推荐安装使用(用处不大)
acme.sh --install-cert -d example.com --ecc --fullchain-file /path/to/fullchain --key-file /path/to/key

实用小技巧

1
openssl rand -base64 32 # 生成随机密码