未找到 Certbot

Certbot not found

我使用以下命令在我的 ubuntu 16.04 机器上安装了 letsencrypt。

sudo apt-get install letsencrypt

现在,我想定义一个 cronjob 以使用以下行自动更新我的证书。

certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"

但我总是遇到错误,找不到命令 certbot。

如果我使用 letsencrypt 而不是 certbot,只要我不使用 --pre-hook--post-hook.

一切正常

如何安装certbot或者是否有 letsencrypt 定义此类挂钩的替代命令?

谢谢

好的,我找到了解决方案..

git clone git@github.com:certbot/certbot.git

cd certbot

./certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start"

你可以试试Let's Certbot.

Let's Certbot 是一个基于 Certbot 构建自动化脚本的工具,用于获取、更新、部署 SSL 证书。

它支持 docker 和非 docker 环境。

GitHub: https://github.com/jinhucheung/letscertbot

这对我有用。当运行具有提升权限的 certbot

时,我必须指定完整路径
sudo /snap/bin/certbot renew --dry-run

TL;DR

尽管我的 $PATH

中有 /snap/bin
echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/games:/snap/bin

但如果不提供完整路径,它就无法与 sudo 一起使用。它抛出以下错误

certbot renew --dry-run
The following error was encountered:
[Errno 13] Permission denied: '/var/log/letsencrypt/.certbot.lock'
Either run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.

如果我(同时在 root 的 $PATH 中也有 /snap/bin)切换到高级用户,它也有效

sudo -i

然后 运行 任何 certbot 命令

请注意,我使用的是 debian 10,并根据教程 https://certbot.eff.org/lets-encrypt/snap-nginx 使用 snapd 作为包管理器 。 =22=]

正如这里所解释的那样https://unix.stackexchange.com/questions/245772/why-running-command-as-sudo-returns-command-not-found这是一种预期和认可的行为:

sudo tries to be safe when executing external commands. the usual workaround is to specify the complete pathname of the program. It's also more secure; it you don't specify the path, it's conceivable that an attacker could create another program that will be run with root permissions.

继续阅读,我发现我的 PATH 不同

env | grep ^PATH
sudo env | grep ^PATH

线程 Command not found when using sudo 提供了多种解决方案(使用自定义 sudo 或更改 sudo $PATH),因此不必指定完整路径。

按照 official instructions 安装 certbot

sudo apt install certbot python3-certbot-nginx

或者,在具有 snap

的较新的 Ubuntu 中
sudo snap install --classic certbot

它将在 $PATH 之后可用。

尝试使用快照删除
sudo snap remove certbot

然后再次安装 sudo snap install --classic certbot

对我来说,以下命令工作正常。

安装快照

sudo apt update

sudo apt install snapd

安装核心

sudo snap install core

安装 Certbot

sudo snap install --classic certbot

sudo ln -s /snap/bin/certbot /usr/bin/certbot

更新 Certbot

sudo certbot renew --dry-run

试试这个 sudo ~/.certbot/bin/certbot certonly --webroot