Sudoers Add User Techhyme

How to Add a User to Sudoers on Ubuntu

In many Linux environments, it’s common to grant sudo access to non-privileged users for performing administrative tasks. This practice ensures that certain actions, typically requiring root privileges, can be executed without granting full root access.

This tutorial will guide you through a step-by-step procedure to add a user to the sudoers list on Ubuntu.

Step 1: Create a New User

The first step involves creating a new user. For this example, we’ll create a user named “chetansoni.” Use the following command:

useradd -m chetansoni

The `-m` option ensures the creation of the user’s home directory if it doesn’t exist.

Add User Sudo Techhyme

Step 2: Set User Password

Set a password for the newly created user using the `passwd` command:

passwd chetansoni

Add User Sudo Techhyme

Step 3: Verify User

Check if the user has been successfully created by inspecting the `/etc/passwd` file:

cat /etc/passwd | grep -i chetansoni

This command will display details such as the username, user ID, group ID, and assigned shell.

Add User Sudo Techhyme

Step 4: Modify User Group

Add the user to the sudo group using the `usermod` command:

usermod -aG sudo chetansoni

This command appends the user to the supplementary group “sudo.”

Add User Sudo Techhyme

Switch to the new user and verify the sudo group membership:

su - chetansoni
sudo whoami

Add User Sudo Techhyme

Step 5: Add User to Sudoers using visudo

While adding the user to the sudo group often suffices, it’s advisable to also add the user to the `/etc/sudoers` file. Use the `visudo` command to open the file:

visudo /etc/sudoers

Add the following line to the file:

chetansoni ALL=(ALL:ALL) ALL

This line grants sudo privileges to the user “chetansoni.”

Add User Sudo Techhyme

Note: Always use `visudo` to ensure there are no configuration errors in the sudoers file.

Step 6: Check Sudo Access

Finally, test sudo access by running a command that requires elevated privileges:

sudo service nginx start

If you encounter an error stating that the user is not in the sudoers file, double-check the entry in the `/etc/sudoers` file:

grep -i chetansoni /etc/sudoers

Following these six steps will enable a non-privileged user to perform administrative tasks on Ubuntu with sudo access. Always exercise caution when modifying user privileges to ensure the security of your Linux system.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply