Answer 1
The drivers drop root privileges long before the serial or USB port is
opened. You’ll need to change the permissions on that port so that
their new user id can access it. Normally this is nobody, but it
may be changed at compile-time by using configure --with-user
or
in the ups.conf
file for driver settings with user=...
.
Read the error message. If you have a permissions mismatch, then you’ll see something like this:
Network UPS Tools - APC Smart protocol driver 0.60 (1.1.7) This program is currently running as youruid (UID 1234) /dev/ttyS2 is owned by user root (UID 0), mode 0600 Change the port name, or fix the permissions or ownership of /dev/ttyS2 and try again. Unable to open /dev/ttyS2: Permission denied
Now is a good time to point out that using nobody is a bad idea, since it’s a hack for NFS access. You should create a new role account (perhaps called ups or nut), and use that instead.
Also, scroll down to the "security domains" question to see an
even better way of restricting privileged operations. Neither the
drivers nor upsd
ever need root powers, and that answer tells you
how to make it work.
Answer 2
You can also specify a user with user=
in the global part of
ups.conf(5). Just define it before any of your [sections]
:
user = nut [myups] driver = mge-shut port = /dev/ttyS0