I want to design a sudo rule that will allow the user ricardo
to update the system using aptitude
, but prevent him from using sudo to run any other command (he's a problem user). Are there any pitfalls to this rule that I'm missing?
ricardo ALL=(root) /usr/bin/aptitude
Ricardo only uses aptitude
, not apt-get
. Also, I don't have Ubuntu installed anywhere at the moment, so I understand that /usr/bin/aptitude
might not be the exact right file to allow.
If there are pitfalls to this rule, how can I improve it?
This command will restrict the user from using
aptitude
for anything but updating the repository cache and performing a safe upgrade of the system.A similar command will allow the user to perform a full upgrade, but nothing more:
Per aptitude's documentation (10.04),
safe-upgrade
:In contrast,
full-upgrade
:Use your best judgement for which the user should be allowed to run. If you're unsure, use the first rule, which only allows
safe-upgrade
.Note that if you want to allow a user to install packages (which greatly reduces any benefit to security, but hypothetically), you need to include a
*
after theaptitude
command, i.e.Otherwise, you will receive an error message that user
ricardo
is not allowed to run the command/usr/bin/aptitude install <package_name>
.You can use
sudo -l
to see which commands a user is allowed to run. For instance, to see which commands ricardo can run:to see whether he can run aptitude,
this will either print the command name as it's expanded by sudo, or exit with code 1 if the user is not allowed to use the command.
This should work in any recent debian-based system for you to test; the syntax is not Ubuntu-specific.
source: man sudo
I can not actually see anything wrong with that sudoers line. Unfortunately, I have not messed around with
sudo
's configuration settings that much, so in that case, my advice may not be reliable. Fortunately, what I can do is give you a line that I do know is safe:This line is guaranteed to only let ricardo execute
aptitude
as root, as long as ricardo is not a member of a sudo-enabled group, such assudo
oradmin
.Source: 8 Ways to Tweak and Configure Sudo on Ubuntu - How-to Geek.