Using sudo to allow non-root users to perform root level functions
This document (7002705) is provided subject to the disclaimer at the end of this document.
SUSE Linux Enterprise Server 12
SUSE Linux Enterprise Server 15
The syntax for using sudo is fairly simple, you specify the name of the command preceded by 'sudo'. For example, if a user needed to run /sbin/chown, you could run it with the command:
sudo /sbin/chown <user_name> <file_name>
Which would then prompt you for the root password and then run the command. You can configure sudo to allow access to files by using the root password, the user's own password, or with no password.
Configuring who's password to use
Here is how to configure each:
1. For non-root user access by entering the root password:
2. For non-root user access by entering their own password:
# In the default (unconfigured) configuration, sudo asks for the root password. # This allows use of an ordinary user account for administration of a freshly # installed system. When configuring sudo, delete the two # following lines: # Defaults targetpw # ask for the password of the target user i.e. root # ALL ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'!
3. For non-root user access by entering no password:
# User privilege specification root ALL=(ALL) ALL <user_name> ALL=NOPASSWD:
Setting up permissions for non-root users
Now that you know how to change what password to use (or not to use), let's move on to permissions.
In the "User privilege specification" section, you can set privileges at the user or group levels. Here is what it looks like by default:
# User privilege specification root ALL=(ALL) ALL # Uncomment to allow people in group wheel to run all commands # %wheel ALL=(ALL) ALL # Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL # Samples # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom # %users localhost=/sbin/shutdown -h now
# User privilege specification root ALL=(ALL) ALL Joe ALL=PASSWD: /bin/chown
# User privilege specification root ALL=(ALL) ALL Joe ALL=PASSWD: /bin/chown -R, /bin/chown -V, /bin/chown -R-V
Notice that there are three separate entries. One that allows -R, one for -V, and one for -R-V. sudo allows will only allow multiple parameters if you add them specifically (and only in the order that you specify), thus the -R-V in addition to the individual parameter listings.
You can also allow some commands to be used with no password while others require a password. Here is an example:
Joe ALL=NOPASSWD: \ /bin/chown -R, PASSWD: /bin/chown -V, /bin/chown -R-V
The same thing can be done for user groups, you just need to put it in the following syntax:
# Uncomment to allow people in group wheel to run all commands # %wheel ALL=(ALL) ALL # Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL # Samples # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom # %users localhost=/sbin/shutdown -h now
You just need to specify the group name with a % in front of it. The same syntax for users applies to groups.
## Read drop-in files from /etc/sudoers.d @includedir /etc/sudoers.d
With above syntax, new configuration could be added without updating /etc/sudoers. For full information, kindly check the manual pages: man sudoers
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:7002705
- Creation Date: 19-Feb-2009
- Modified Date:11-Aug-2022
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com