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.
Environment
SUSE Linux Enterprise Desktop 10
SUSE Linux Enterprise Server 11
SUSE Linux Enterprise Server 12
SUSE Linux Enterprise Server 15
SUSE Linux Enterprise Server for SAP Applications 12
SUSE Linux Enterprise Server for SAP Applications 15
Microsoft Azure Virtual Machines
Situation
Resolution
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:
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:
# 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
3. For non-root user access by entering no password:
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:
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
To give privileges to users, add users to the area under the "User privilege specification". As an example, to give a user named Joe privileges to run chown, you would add the following entry:
root ALL=(ALL) ALL
Joe ALL=PASSWD: /bin/chown
root ALL=(ALL) ALL
Joe ALL=PASSWD: /bin/chown -R,
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:
PASSWD:
/bin/chown -V,
/bin/chown -R-V
With the above configuration, the /bin/chown -R command will not require a password, /bin/chown -V and /bin/chown -R-V will require a password to run, but they will be allowed.
The same thing can be done for user groups, you just need to put it in the following syntax:
# %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.
Disclaimer
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:31-Mar-2021
-
- SUSE Linux Enterprise Desktop
- SUSE Linux Enterprise Server
- SUSE Linux Enterprise Server for SAP Applications
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback@suse.com