Stillmatic1985
Stillmatic1985

Reputation: 1912

Certbot not found

i installed letsencrypt on my ubuntu 16.04 machine with following command.

sudo apt-get install letsencrypt

Now, i want to define a cronjob to automatically renew my certs with following line.

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

But i always get the error, that the command certbot could not be found.

If i use letsencrypt instead of certbot everything works fine as long as i dont use the --pre-hook and --post-hook.

How to install certbotor is there an alternative command for letsencrypt to define such hooks?

Thanks

Upvotes: 12

Views: 58382

Answers (7)

mrts
mrts

Reputation: 18925

Follow the official instructions and install certbot with

sudo snap install --classic certbot

or, in older Ubuntus that don't have snap, with

sudo apt install certbot python3-certbot-nginx

It will be available in $PATH after that.

Upvotes: 8

MGE
MGE

Reputation: 853

try this sudo ~/.certbot/bin/certbot certonly --webroot

Upvotes: 0

Mohamed Yakout
Mohamed Yakout

Reputation: 3036

For me the following commands working fine.

Install snap

sudo apt update

sudo apt install snapd

Install Core

sudo snap install core

Install Certbot

sudo snap install --classic certbot

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

Renew Certbot

sudo certbot renew --dry-run

Upvotes: 22

Nitish Kumar
Nitish Kumar

Reputation: 111

try to remove using snap
sudo snap remove certbot

and then install again with sudo snap install --classic certbot

Upvotes: 1

This worked for me. I have to specify full path when running certbot with elevated privileges

sudo /snap/bin/certbot renew --dry-run

TL;DR

Although I have /snap/bin in my $PATH

echo $PATH

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

But without providing full path it does not work with sudo. It throws the following error

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.

and it also works if I (while having /snap/bin in root's $PATH as well) switch to power user

sudo -i

and then run any certbot command

Kindly note I'm on debian 10 and using snapd as package manager according to the tutorial https://certbot.eff.org/lets-encrypt/snap-nginx.

As explained here https://unix.stackexchange.com/questions/245772/why-running-command-as-sudo-returns-command-not-found this is kinda expected and approved of behaviour:

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.

Going on reading further I can see that my PATHs are different

env | grep ^PATH
sudo env | grep ^PATH

There are several solutions (use custom sudo or change sudo $PATH) provided at the thread Command not found when using sudo so one does not have to specify full path.

Upvotes: 1

Kumho Cheung
Kumho Cheung

Reputation: 1

You can try Let's Certbot.

Let's Certbot is a tool builds automated scripts base on Certbot for obtaining, renewing, deploying SSL certificates.

It supports docker and non-docker environments.

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

Upvotes: 0

Stillmatic1985
Stillmatic1985

Reputation: 1912

Ok i found the solution..

git clone [email protected]:certbot/certbot.git

cd certbot

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

Upvotes: 5

Related Questions