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.