I'd like to allow certain users to su to another user account without having to know that account's password, but not allow access to any other user account (i.e. root).
For instance, I'd like to allow Tom the DBA to su to the oracle user, but not to the tomcat user or root.
I imagine this could be done with the /etc/sudoers file - is it possible? If so, how?
Yes, this is possible.
In /etc/sudoers the item immediately following the equals is the user that the command will be allowed to execute as.
The user (tom) can type sudo -u oracle /bin/chown tom /home/oracle/oraclefile
Add to your /etc/sudoers something like
Then user tom should be able to use sudo to run things as user oracle with the -u option, without letting tom
I.e. getting a shell as user oracle (well, given that your sudo is new enough to have the -i option).
To ONLY provide the capabilities in the question, add the following to /etc/sudoers:
Then tom can:
I needed to do this to a system recently and had a hard time finding my notes on the alternate setup i used years ago that also allowed the syntax
su <user>
. In my situation I needed to allow multiple users tosu
to a specific user.Create a group using
addgroup <groupName>
that other users will be able tosu
to without a password. Then add that group to each user that you want to be able tosu
to that user without a password:usermod -a -G <groupName> <userName>
(orusermod -a -G oracle tom
). The group changes might not take affect until next login.Note: In your case, you already have the group because
oracle
group would have been created when you made the oracle user withadduser oracle
.Now edit
/etc/pam.d/su
and under the following:..add auth rule lines so the section looks like this:
Replace
<groupName>
withoracle
in this case. This will allow any user that is part of the<groupName>
tosu <groupName>
Now
tom
cansu oracle
and if you need to give other users the same access, add them tooracle
group.similar question here