You can use visudo
to control user access and what functions can they use as well.
Here's an example
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
ubuntu ALL=/bin/sh,/usr/bin/*,/usr/sbin/*,/usr/bin/passwd [A-Za-z]*,!/usr/bin/passwd root,!/usr/bin/su,!/usr/sbin/visudo, /sbin/*, /bin/*
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL, !/usr/bin/passwd root
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
In the above config. User ubuntu
has restrictions as well as sudo
group also has restrictions.
For instance, ubuntu
can do following:
- Run command in
/bin/sh
- Run any command in
/usr/bin/*
- Run any command in
/usr/sbin/*
- Change password of any users
/usr/bin/passwd [A-Za-z]*
But ubuntu
cannot do following:
- Change
root
password !/usr/bin/passwd root
- Become superuser
!/usr/bin/su
- Update
visudo
itself !/usr/sbin/visudo
You can also do this with groups
as well. I.E sudo
group can do anything but change the root
password.
Update
If you really wanna go the extra mile to stop someone accessing another user. I would do this.
- Find the next available
group
ID for new group
getent group
use this command and find the next biggest number group id available. Normally it's next number after the last user you've added. In my case it is 1002
, after my last added users user1:x:1001:
.
- Then create a new group with the next available ID.
- In my case I did the following.
sudo groupadd -g 1002 restricted
- Then update the
viduso
to add your required restrictions.
- In my case, I added the following line after the
%sudo
line.
%restricted ALL=(ALL:ALL) ALL, !/usr/bin/su, !/bin/su
.
- Last add the user to the group.
sudo adduser user1 restricted