How to Add a User to Sudoers on openSUSE

When installing openSUSE, the user account that was created during the initial setup has sudo rights. However, there may be a need to add additional sudo users or make the default user have sudo rights. This is a straightforward process with a few commands.

In the following tutorial, you will learn to add a user to the sudoers group on any openSUSE system.

Prerequisites

Updating Operating System

Update your openSUSE operating system to make sure all existing packages are up to date:

sudo zypper refresh
Advertisement

Changing to Root Account (su command)

To create new sudo users, you will need to switch to root using the su command. By default, this should have been set when installing openSUSE. If you have forgotten the root password while in sudo mode, you can reset it as follows.

sudo passwd root

Next, you will be prompted to enter your password for your sudo account, then once verified, enter a new root password.

Example output:

Changing password for user root.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

Now that your root password has been set, switch to root using the following command su:

su

You will be prompted for the root password. Once entered, you will see the username has changed to root.

Example:

How to Add a User to Sudoers on openSUSE

Create and User Account

The first step is learning how to add a new user account. Ideally, you can grant permission to an existing account, but you will learn to add a user from scratch for the tutorial.

First, create the user account <example username>, replacing the sample with the user name you want to add.

useradd <example username>

Example:

useradd josh

Next, you will need to set the password for the user name just added.

In the tutorial example, the username is “josh.”

passwd josh

Example:

How to Add a User to Sudoers on openSUSE
Advertisement

Add New User To Sudoers Group

In the next part of the tutorial, now that you have learned how to add a user, you can give the new user that you named or an existing username sudoers access by typing the following command:

usermod -aG wheel <example username>

Example using our name we created:

usermod -aG wheel josh

It is a good idea to check if the username was successfully added to the sudoers group. To do this, run the id command:

id <username>

Example using our name we created:

id josh

Example output:

How to Add a User to Sudoers on openSUSE

An alternative is to use the gpasswd command as follows:

gpasswd -a <example username> wheel

Example using our name we created:

gpasswd -a josh wheel

Example output:

Adding user josh to group wheel

Confirm & Test New Sudo User

Now that you have successfully added the user you wanted to have sudo access to, it is time to test the account. This can be done again by using the su command but by adding the username along with the command.

Login to sudo user as follows:

su <example username>

Example using our name we created:

su josh

Now, confirm the username with the sudo command along with whoami:

sudo whoami

You will then be prompted to type in the sudo username you are using and its password. Once entered and confirmed, you will see the following output:

How to Add a User to Sudoers on openSUSE

Congratulations, you have added a new username to the sudoers group.

Advertisement

Comments and Conclusion

You have learned how to add users to your openSUSE operating system and add sudo permissions in the tutorial. Overall, this tutorial should work for all current versions of openSUSE that are supported and is recommended only to give permissions to trusted users as they will have access to sensitive files with the permit provided by sudo.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x