I regularly need to drop a postres database and recreate it. It has to be done as
postgres user as following:
$ sudo -u postres dropdb my_database
I thought of adding sudoers rules for not being asked a password. Usually I proceed by creating a file in
/etc/sudoers.d/ with a rule like this one:
Cmnd_Alias DROP_DB = /bin/bash -l -c dropdb*, /usr/bin/dropdb* emilio ALL = NOPASSWD: DROP_DB
But in this use case, I need to run the command as postgres user and it doesn't work.
What is the proper way to run a command as a different user without being asked a password?
EDIT: This might be a duplicate but it brings a different solution using
visudo which is interesting.