I'm currently trying to set up a system user on my Ubuntu 18.04.1 LTS server to run a specific service from its home directory and be used with
sudo -u USER to execute a command sometimes.
I've created the user with this command:
sudo useradd -d /opt/USER -m -r -s /usr/sbin/nologin USER
passwd -S USER shows this:
USER L 12/30/2018 -1 -1 -1 -1
First of all, I don't understand why the password is L (locked) instead of not set at all (NP). Not that it matters, I think, since I don't want to login as that user anyway.
Now, I want to be able to run a command as that user, but only me.
I can use
sudo -u USER echo Test without issues, but anyone can run that command. Restricting access to sudo to only my account is currently not possible.
How can I restrict sudo to only myself with that user?