Is there someway to restrict su
to a specific group of users?
Upon searching over the web, I came across IBM AIX's concept of sugroup
. Whenever a user is created, attribute sugroup
can be set; and only members of this group are allowed to su to that user.
sugroup
can help me solve my problem by creating a group which contains only certain users allowed to su. Assigning sugroup
means users outside this group are not permitted to be su-ed to by other users. But this concept of sugroup
is not available in Ubuntu. How can it be achieved in Ubuntu?
I made following entry in /etc/pam.d/su
:
auth required pam_wheel.so group=sulogin
I created following:
- a group called
sulogin
which is for users allowed to su - users who don't belong to
sulogin
areuser1
anduser2
- users who do belong to
sulogin
areadmin1
andadmin2
Now when I am logged in as user1
and try to su to admin1
or admin2
, I am not permitted to do so. This is as per my requirement. When I am logged in as user1
and try to su to user2
, I am not permitted to do this. This is not as per my requirement (although my requirements were not clearly mentioned in the original question).
I need to restrict all the users who are not in group sulogin
from su-ing to any user who belongs to sulogin
group. Basically, 2 levels of su privilege. So in the above mentioned scenario:
user1
should be able tosu
touser2
and vice-versauser1
oruser2
should not be able tosu
toadmin1
oradmin2
admin1
should be able tosu
touser1
oruser2
The equivalent is possible on Ubuntu, it's just not enabled by default. Check out
/etc/pam.d/su
:So, uncomment this
auth
line, thensu
will be restricted to members of grouproot
. Or uncomment and addgroup=sulogin
, if you want to restrict to thesulogin
group.