sudo is a utility to switch users and allow specific things. Just a tool: one can write good policy or horrible policy with it. Not the only tool that can do this, doas is an alternative.
Principles of least privilege apply, avoid the superuser root where possible. Users becoming root has a risk they break something, bring it out of compliance, or steal secrets they should not have access to.
It makes sense for the system administrator to start a root shell with sudo -i
, they are supposed to be able to do anything to the host. Less sense for an application analyst or developer to have full control of a managed server. They can get confined, less privileged users instead. And switch to these not root users with the sudo -u user
option.
Consider an application called thing. Create a user and group service account for this, also called thing. Create a directory for it, owned by the application user. And because we the sysadmins have a good habit of not being logged in as root, use sudo to become root and accomplish this.
sudo install --directory --owner=thing --group=thing /opt/thing
After a tweak to sudoers policy, the analyst can become the user with sudo -u thing
and do what they like under this tree.
Note that most modern software is released as discrete archives. Debian deb, EL rpm, containers, other package formats. For Java, openjdk has builds in any of those formats.
You could package your stuff such that it is easy for anyone to provision a VM or container with it. But that's a topic for a different question.