When specifying commands allowed via sudo
, there are basically two easy options:
- allow a specific command with any parameters, or
- allow a specific command with an exactly specified set of parameters only.
As a result, allowing both sudo su - superman
and sudo su superman
requires two entries in the sudoers
file. It looks like your administrator has only provided you with one of them.
The sudoers
file syntax does not really let the administrator specify a specific command with wildcard- or regexp-limited options, because those specifications would be an all too easy to abuse. As Andrew said, better safe than sorry is the approach here.
However, note that sudo su superman
requires sudo
to allow the original user to run su superman
as root. Effectively, there will be two identity transitions instead of just one: first from original user to root by sudo
and then from root to superman
by su
. The specification would look like this in the sudoers
file:
original_user ALL=(root) su superman
On the other hand, the sudoers
syntax has a much easier way to allow the user to run any commands as a specific user, if the user is not too fixated to the use of the su
command.
If the sudoers specification is written like this:
original_user ALL=(superman) ALL
then the user can use sudo -u superman -s
to achieve a close (but possibly not exact) equivalent of sudo su superman
and sudo -u superman -i
to achieve an exact equivalent of sudo su - superman
.
Why people don't use this, but instead insist on using sudo su -
constructs? Because the -i
option did not exist in older versions of sudo
!
It only appeared sometime after year 2000, so there's plenty of old literature that still recommends the now-obsolete sudo su -
construction. And of course, old Unix users and administrators may have that in muscle memory, so they'll use it without thinking.
/etc/sudoers
? If so, [edit] your question and add the output ofsudo grep -w su /etc/sudoers
. Also [edit] and add your distribution. – terdon Dec 02 '15 at 14:01sudo -l
will be helpful, it will show what commands you're allowed to execute even if you can't read/etc/sudoers
and/etc/sudoers.d
. – Ulrich Schwarz Dec 02 '15 at 14:04