Adding a user to the sudoers file grants them administrative privileges. Here's a quick guide:


1. Log in as a Root User or a Sudo User

Ensure you have root access or an existing sudo user.

su -  # Switch to root
# OR
sudo -i  # Open a root session

2. Add the User to the sudo Group

On most Linux distributions, users in the sudo group have administrative privileges.

usermod -aG sudo username

Replace username with the desired user's name.


3. Verify the User Has Sudo Access

Switch to the user and test their sudo privileges:

su - username
sudo whoami

If successful, it will return root.


4. Optional: Edit the Sudoers File

For advanced permissions, edit the sudoers file safely with visudo:

sudo visudo

Add a specific rule, e.g., to allow a user to run all commands:

username ALL=(ALL:ALL) ALL

Save and exit (Ctrl+O, Enter, Ctrl+X).


Now your user can run administrative commands securely!

Disclaimer: At MojaLab, we aim to provide accurate and useful content, but hey, we’re human (well, mostly)! If you spot an error, have questions, or think something could be improved, feel free to reach out—we’d love to hear from you. Use the tutorials and tips here with care, and always test in a safe environment. Happy learning!