How to Give A User Sudo Access in Linux: Complete Guide

how to give a user sudo access in linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

While supervising or managing a Linux system, you may need to create users with various degrees of administrative privileges, also termed ‘roles.’ Understanding how to give a user sudo access in Linux is critical for every Linux administrator. For example, while adding a new user, or even for an existing user, assigning sudo privileges on Linux permits the user to run commands that need super-user authorization. This article aims to explain the steps to grant sudo privileges to a user in Linux systems in depth along with illustrative codes and insights.

Let’s look into the steps of how to get sudo access on Linux so that your users can perform administrative duties without any hassle!

What is Sudo Access in Linux?

In Linux, sudo is short for superuser do and is a command that allows users to run programs or commands with permissions on behalf of a restricted user with increased privileges. This is used very frequently to install software and perform general maintenance on the system. Granting sudo privileges to a user in Linux allows the user to perform a range of tasks that would otherwise require root access without logging on as the root user.

In Linux by default, only the root user can perform certain system-level commands due to the limited sudo access. However, it is rather simple to modify these configurations to permit other users to have root access for specific actions.

How to Give A User Sudo Access in Linux

Step 1: Create user in Linux with Sudo Access

If you do not have an existing user and want to create a new user with sudo privileges, you can do this by taking the following step. Here is how to give sudo access to user in Linux

sudo adduser newuser

The above command will create a user i.e. newuser.

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Step 2: Add User to Sudo Group

Most distributions of Linux allow you to utilize groups as a means of providing users sudo access. The most simple method of providing a user sudo access is through group addition. This enables the user to perform all low-level tasks associated with running commands as the root user.

To add a user to the sudo group, issue this command:

sudo usermod -aG sudo newuser

This command adds “newuser” to the sudo group. The flag -aG indicates the group that the user is to be added without removing them from the other groups that they belong.

Step 3: Confirm Sudo Privileges of the User

Once a user is added in the sudo group, you can ascertain whether said user has sudo privileges by evaluating the group memberships with the command given below:

groups newuser

You should see something like this in the output:

newuser : newuser sudo

Now, you are certain that the user is active in sudo group and is being empowered with sufficient permissions.

Step 4: Evaluate Sudo Privileges

After, confirm that the user is able to log in under newuserid, try using sudo to determine if they possess the privilege. Log in as the new user:

su - newuser

Then, try executing a command using sudo, like:

sudo ls /root

If the presumption of the user having sudo access is correct, the user will be prompted to furnish their password. Once they enter the password, the user is expected to successfully execute the command and view content within the /root directory.

How to Access Sudo in Linux

To access sudo in Linux, a user must be a member of the sudo or wheel group, depending on your system’s configuration. Once a user has been granted sudo access through the group membership, they can run administrative commands by prefixing them with sudo. For example:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

sudo apt update

In Debian-based systems, a command given is capable of updating the list of packages, which the system is designed to execute. Whenever the user commands the system, it seeks verification from the user, and if the credentials provided are valid, only then will additional commands be executed with superuser system access.

To provide a particular user with a specific command in order for them to have an easier time using Linux, the sudoers file can be adjusted. That being said, doing this incorrectly can put you at risk of being locked out.

Providing users the ability to execute certain commands can be done by changing a file through the command visudo which allows you to edit the sudoers file. This edit can only be done with correct syntax so there is no threat of adding extra risk for lockout.

sudo visudo

To assign the newuser the permission to only run as superuser the utility apt, use the following command:

newuser ALL=(ALL) NOPASSWD: /usr/bin/apt

This setup will let the user run apt without a password prompt.

Troubleshooting Common Issues

So far, we have done with how to give a user sudo access in Linux. Now, we have to discuss some common issues. Troubleshooting sudo access for users can prove quite challenging. Here are pointers that will help you resolve such issues.

1. Users May Not Belong to the Sudo Group

If users cannot execute commands with sudo, check their group membership with the following command:

groups newuser

In the case where the user is not in the sudo group, follow the Add user procedure outlined above.

2. Manual Syntax errors in the Sudoers file

If you are reading this, it is likely you modified the /etc/sudoers file and can no longer sudo into your system. This is how to undo the damage caused while editing the file:

Boot the system in single-user mode.

Run visudo to fix your syntax error.

3. Sudo Not Installed

The sudo command may be absent in certain installations. It can be installed with this command:

sudo apt install sudo # For Ubuntu/Debian

sudo yum install sudo # For CentOS/RHEL

The Importance of CyberPanel in Giving Sudo Access to User in Linux Systems

How to give a user sudo access in Linux with CyberPanel

Speaking of managing users and permissions, CyberPanel i.e. a robust web hosting control panel takes the role. It provides an intuitive interface that makes it easy for system administrators how to give a user sudo access in Linux without editing any configuration files. CyberPanel’s interface is intuitive, automating the addition of users to groups and the management of sudo privileges. This makes CyberPanel stand out among people who have a preference toward GUI over command line interface.

FAQs: How to Give a User Sudo Access in Linux

1. How Do I Grant A New User Sudo Privileges In Linux?

To grant new users access to sudo privileges, add them to the sudo group using the command: 

sudo usermod -aG sudo username

2. How Do I Check If A User Has Sudo Privileges?

You can use the groups command to see if the user belongs to the sudo group. Simply type: 

groups username

3. Is It Possible To Restrict Sudo Access So It Only Works With Certain Actions?

Editing certain permissions is achievable by modifying the system’s sudoers configuration file located in the /etc directory with visudo.

4. What If the User Cannot Use Sudo After Adding Them to the Group? 

Checking the user’s assigned groups checks if they were given the necessary permissions and if the sudo package is available. To check this use the group’s username. 

5. How Do I Access Sudo As A User? 

Any user who has been assigned sudo access is able to run commands using it by placing sudo before the command, for example, typing sudo ls /root.

Conclusion: Empower Your Linux Users With Sudo Access

To sum up, knowing how to give a user sudo access in Linux is vital in helping you secure your operating system. No matter your proficiency level, these procedures will work well in creating an efficient approach to managing admin functions. 

With such processes, any level of proficiency can be useful in performing system security settings. Get started on adjusting user permissions right away! Set up sudo access in Linux to give more responsibility to your team when it comes to system administration.

Hasib Iftikhar
I'm Hasib Iftikhar, a dedicated technical writer at CyberPanel, joining the team in July 2024. With three years of extensive experience in content writing, I specialize in copywriting, article writing, guest posting, affiliate content writing, and SEO. My expertise ensures that each piece of content I create is engaging, informative, and optimized for search engines, helping businesses enhance their online presence and reach their target audience effectively.
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!