Understanding Sudo Privileges in Ubuntu
In Ubuntu Linux, system security revolves around the concept of user permissions. Standard users can browse files, run applications, and configure their own local settings, but they cannot perform administrative tasks like installing software, configuring firewalls, or modifying system-wide configuration files.
To execute administrative commands, a user must use the sudo prefix before their command, which stands for "Superuser Do." However, typing sudo will only work if the user has been explicitly granted administrative privileges. In Ubuntu, this is achieved by adding the user to a specific group called the sudoers group.
If you need to give a new team member, a secondary account, or an automated script administrative rights, you must add them to this group using the command line.
Requirements Before Starting
To add a user to the sudoers group, you must meet two requirements:
- The user account you want to grant privileges to must already exist on the Ubuntu system.
- You must be logged into an account that already has sudo privileges (or the root account) to execute the command.
The Best Method: Using the usermod Command
The safest and standard way to grant sudo access in Ubuntu is by adding the user to the "sudo" group using the usermod command. You do not need to manually edit complicated configuration files.
- Open your terminal application (or connect to your server via SSH).
- Type the following command, replacing
usernamewith the actual name of the account you want to upgrade:sudo usermod -aG sudo username - Press Enter. You will be prompted to type your own password to verify your administrative access.
Understanding the command flags:
-astands for "append." It tells the system to add the user to a new group without removing them from their existing groups.-Gstands for "groups." It specifies which group the user is being added to (in this case,sudo).
How to Verify the User Has Sudo Privileges
Because the usermod command rarely provides a confirmation message upon success, it is important to verify that the user was successfully added to the group.
You can check the groups a specific user belongs to by typing:
groups username
The output will look something like this:
username : username sudo
If you see sudo listed in the output, the user now has administrative rights.
How the New User Can Test Their Access
If the user is currently logged in while you make this change, they must completely log out and log back in for the new group permissions to take effect. If they are connected via SSH, they need to disconnect and reconnect.
Once they log back in, they can test their access by trying to read a protected system file, such as the auth log:
sudo cat /var/log/auth.log
The system will prompt them for their own password. If the command executes successfully and prints the log file, their sudo privileges are working perfectly.
Alternative Method: Using the adduser Command
While usermod is the standard tool across most Linux distributions, Ubuntu provides a slightly more user-friendly wrapper script called adduser.
If you prefer a simpler syntax, you can add a user to the sudo group by typing:
sudo adduser username sudo
The output will clearly confirm the action: "Adding user ‘username’ to group ‘sudo’ … Done." Both methods achieve the exact same secure result.