How to Create Sudo User in openSUSE Linux

The sudo command allows a user to administer a Linux system with the security privileges of another user, by default, the superuser or root.

In this guide, we will walk you through the process of creating a sudo user in openSUSE i.e create a user and grant them privileges to invoke the sudo command.

For this guide, we will use openSUSE Leap 15.3, the latest release on which the sudo command comes pre-installed. However, if this is not the case for you and the sudo command isn’t installed on your openSUSE operating system, install it as follows.

Install Sudo in openSUSE Linux

First switch to the root account, using the su command, enter the root password when prompted, and then run the zypper command to install sudo as shown:

$ su - 
# zypper in sudo

This guide also assumes that you have a freshly installed openSUSE operating system on your computer.

Create Sudo User in openSUSE Linux

Start by creating a user account (called sysadmin in this example), using the useradd command, and create a secure password for the user as follows. The -m flag instructs to create the user’s home directory.

Note that the user tecmint is the default administrative user that can invoke sudo. Therefore we are using it to create another administrative user that can invoke sudo as well.

$ sudo useradd -m sysadmin
$ sudo password sysadmin
Create Sudo User in openSUSE
Create Sudo User in openSUSE

Next, add the user sysadmin to the administrative group called wheel using the usermod command as shown.

In this command, the -a flag means adding the user to the supplementary group specified by the -G flag. Then check the sysadmin’s groups using the groups’ command:

$ sudo usermod -aG wheel sysadmin
$ sudo groups sysadmin
Add User to Wheel Group
Add User to Wheel Group

Configure Sudo Access and Wheel Group in Sudoers File

Now you need to configure the wheel group to allow users who belong to it to execute any command using sudo. Open the sudoers file for editing by running the following command (by default, visudo uses vim as an editor):

$ sudo visudo

Look for the 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'!

and comment them out as shown in the following screenshot.

Configure Wheel Group
Configure Wheel Group

Also, look for the following line.

# %wheel ALL=(ALL) ALL

and uncomment it to allow members of the group wheel to execute any command by invoking the sudo command:

%wheel ALL=(ALL) ALL
Enable User to Use Sudo Command
Enable User to Use Sudo Command

Save the changes in the sudoers’ file and close it.

Note: After the recent changes, the default user account on a freshly installed system is disabled from sudo access. In this case, the user tecmint can no longer invoke the sudo command unless the user is added to the wheel group.

Testing Sudo User in openSUSE Linux

To test if the newly created user account can invoke the sudo command, switch the account using the su command, then run any command using sudo.

$ su - sysadmin
$ sudo zypper install git
Test Sudo User in openSUSE
Test Sudo User in openSUSE

That’s all! In this guide, we looked at how to create a sudo user in the openSUSE Linux distribution. As usual, reach us via the comment form below for any questions or comments.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.