Automating Backblaze?

Glad to help. Now that I’m back at my Mac, I can add that the commands I have added to sudoers are these two lines.

%admin ALL=NOPASSWD: /bin/launchctl load /Library/LaunchDaemons/com.backblaze.bzserv.plist

%admin ALL=NOPASSWD: /bin/launchctl unload /Library/LaunchDaemons/com.backblaze.bzserv.plist

which will allow you to do

sudo /bin/launchctl unload /Library/LaunchDaemons/com.backblaze.bzserv.plist

or

sudo /bin/launchctl load /Library/LaunchDaemons/com.backblaze.bzserv.plist

without having to enter your password.

How to use a sudoers file

If you aren’t familiar with the sudoers file, BE CAREFUL. It’s dangerous. If you muck up the /etc/sudoers file, it can be hard to undo.

Following best practices, I do not edit the main /etc/sudoers file itself, but I have a separate file at /etc/sudoers.d/tjluoma instead.

You can name your file whatever you want (I’ll use “whatever” as a placeholder) , but it has to be owned by root:wheel and it has to be chmod 440. I also think the name has to be all lowercase with no extension (i.e “.txt”).

sudo touch /etc/sudoers.d/whatever
sudo chown root:wheel /etc/sudoers.d/whatever
sudo chmod 440 /etc/sudoers.d/whatever

once you have the file in place, you want to edit it using the visudo command, such as:

EDITOR=nano sudo visudo -f /etc/sudoers.d/whatever

Because visudo will syntax-check the file for you.

n.b: Unless you know that your $EDITOR is set, you’ll want to use EDITOR=nano otherwise you’ll end up having to use vi which is basically a torture device masquerading as a unix program; despite this, some zealots will tell you that you should learn to use vi because some day the world might explode and vi might be your only option. Learn to ignore those people.

You can check the syntax of your sudoers file (and make sure it’s being checked) by running:

sudo visudo -c

which will show you all of the files that it sees, and will tell you if they are OK or not. Here’s what it looks like on my system:

% sudo visudo -c
/etc/sudoers: parsed OK
/private/etc/sudoers.d/503: parsed OK
/private/etc/sudoers.d/tjluoma: parsed OK
/private/etc/sudoers.d/traceyluoma: parsed OK

I hope this helps. Adding things to the sudoers file is definitely a “power user” move, but, hey, that’s why we’re here, right ;-?

1 Like