How to Grant Sudo Privileges to Regular Users on Linux
This guide explains why ordinary Linux users need sudo, how to safely edit the /etc/sudoers file with visudo, interprets each field in typical sudoers entries, and shows step‑by‑step examples for adding both password‑prompt and password‑less sudo access for a new user.
Background
On Linux systems it is common to avoid logging in as the root user. When a command requires root privileges, the sudo command is used to temporarily elevate the current user's permissions.
If a regular user is not listed in the sudoers configuration, attempting sudo will produce an error such as "user is not in the sudoers file".
Sudo Permission Configuration
The full name of sudo is super user do, meaning the command runs with root privileges. Whether a user can run sudo is determined by entries in the /etc/sudoers file. /etc/sudoers is a plain‑text file with a strict syntax; it should be edited with the visudo command rather than directly with vim or vi. Only the root user can execute visudo.
Switch to the root account and run: # visudo This opens the /etc/sudoers file for editing. A typical bottom section looks like:
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
ubuntu ALL=(ALL:ALL) NOPASSWD: ALLExplanation of each column:
First column: username (e.g., root, ubuntu).
Second column (left of =): ALL means the user may log in from any host.
Third column (right of =): ALL indicates the user may run any command as root.
The NOPASSWD keyword (shown for the ubuntu user) allows sudo without prompting for a password.
If a user receives the "not in sudoers" warning, they simply lack an entry in this file.
To grant sudo rights to a new user (e.g., test_user) with the default password prompt, add the following line to /etc/sudoers:
test_user ALL=(ALL:ALL) ALL # test_user must provide password for sudoFor password‑less sudo, use:
test_user ALL=(ALL:ALL) NOPASSWD:ALL # no password required for sudoAfter editing, exit and save with :wq. Switch to test_user and prepend sudo to commands that need root privileges, for example:
[test_user@host ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
903734808a1e hello-world "/hello" About an hour ago Exited (0) About an hour ago happy_jenningsThe command now executes successfully, confirming that sudo is properly configured for the user.
Conclusion
For temporary privilege elevation, simply add the appropriate line to /etc/sudoers using visudo. Editing the file directly with vi or vim is discouraged because visudo validates syntax and prevents configuration errors.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
