Add Sudo User and Permissions in Linux

How To Add Sudo User and Permissions in Linux

Sudo user in Linux will have permissions similar to a root user. With full sudo privileges, a user will be able to perform any operations on the Linux system.

It is very important to categorize a user as a sudo user based on the use case.

In this guide, we will look in to the following.

  1. Create a new Linux user
  2. Adding full sudo privileges to a user
  3. Adding sudo privileges for specific command execution.

Create a new Linux user

Step 1: Login to your server as root.

Step 2: Create a user using useradd command. Replace username with your custom user.

Step 3: Set a password for the user.

You will be prompted for updating the new password. Enter the required password.

Add sudo Privileges to a User

Now lets make our new user or an exiting user a sudo user.

Step1: Add the user to wheel group.

Note: If a user is part of wheel group, he can run any command as a super user.

Step 2: Execute visudo command to open /etc/sudoers file.

Step 3: Make sure the following line is uncommented in the file.

By default, even if a user is part of wheel group, you need to provide the password every time you run a command as sudo. If you need password less sudo access, you need uncomment the following where it has NOPASSWD and save the file using ESC + w + q + !

Step 4: Now lets test the sudo user by logging in as the user.

Now, try running sudo commands. It should work based on your password preferences (with or without password) you set for wheel group.

Adding sudo privileges for specific command execution.

There are scenarios where you might want only specific commands to be run a sudo privileges for a specific user. Lets see how we can achieve it.

You can group the set of commands to be run under Cmnd_Alias

For example, if you open the /etc/sudoers file, you can find the following aliases.

Lets say, you want a user to have only permissions to run commands under the SERVICES alias, you need to have the following entry in the /etc/sudoers file

Note: You can have custom commands in aliases the you create under Cmnd_Alias

Related

1. If, else and ifelse:[crayon-5dd2a68d9eed9043669683/]2. Conditional statement using ternary…

Read more

Class: Class is a way to organize the data. For instance , you want to write a program to display  the names…

Read more

When you start learning powershell you wont be knowing all the commands. So the help system will let you discover…

Read more
About

The Best Tutorials & Tips to Speedup Your DevOps Workflow.

Created by Bibin Wilson.