You configure sudo privileges for specific users by editing the sudoers file or adding a custom file under /etc/sudoers.d. Here’s how:
Step 1: Edit the sudoers File
- Open a terminal and log in as a user with administrative privileges.
- Use
visudoto safely edit thesudoersfile. This command checks syntax and prevents lockouts:
sudo visudo - Find the section where user or group privileges are defined. You’ll see lines like:
root ALL=(ALL:ALL) ALL - Add a new entry for the user. To grant
user1full sudo privileges:
user1 ALL=(ALL:ALL) ALL ALL=(ALL:ALL) ALLmeans the user can run any command as any user or group on any host.
Step 2: Grant Limited Privileges (Optional)
To restrict a user to specific commands, add a rule like this:
user1 ALL=(ALL) NOPASSWD: /bin/systemctl restart apache2.service
NOPASSWD lets the user run that command without a password. Replace the command path with the full path of the executable you want to allow.
Step 3: Use the /etc/sudoers.d Directory
Instead of editing the main sudoers file, create a custom file for the user:
- Create the file with
visudo(recommended) or your preferred editor:
sudo visudo -f /etc/sudoers.d/user1 - Add the necessary rules. For full access:
user1 ALL=(ALL:ALL) ALL - Save and exit. The file is automatically included.
Step 4: Test the Configuration
- Switch to the configured user:
su - user1 - Run a command with
sudo:
sudo whoami - If configured correctly, the command executes and returns
root.
Important Notes:
- Always Use
visudo: Editingsudoersorsudoers.dfiles withoutvisudorisks syntax errors that can lock you out. - Minimal Privileges: Grant only what’s necessary. Avoid full
sudoaccess unless required. - Audit Regularly: Review
sudoconfigurations periodically for security and compliance. - Log Monitoring: Check
/var/log/secure(RHEL/CentOS) or/var/log/auth.log(Debian/Ubuntu) forsudousage.

Ali YAZICI is a Senior IT Infrastructure Manager with 15+ years of enterprise experience. While a recognized expert in datacenter architecture, multi-cloud environments, storage, and advanced data protection and Commvault automation , his current focus is on next-generation datacenter technologies, including NVIDIA GPU architecture, high-performance server virtualization, and implementing AI-driven tools. He shares his practical, hands-on experience and combination of his personal field notes and “Expert-Driven AI.” he use AI tools as an assistant to structure drafts, which he then heavily edit, fact-check, and infuse with my own practical experience, original screenshots , and “in-the-trenches” insights that only a human expert can provide.
If you found this content valuable, [support this ad-free work with a coffee]. Connect with him on [LinkedIn].


