How to Configure Passwordless sudo Access in Linux (RHEL/Ubuntu Guide)


3 views

In controlled environments like development labs or personal workstations, repeatedly entering sudo passwords can disrupt workflow. Passwordless sudo provides smooth administrative access while maintaining security boundaries.

The sudo configuration lives in /etc/sudoers. Never edit this directly - always use visudo which validates syntax before saving:

sudo visudo
# Opens the protected sudoers file in your default editor

For Red Hat-based systems, add this line for a specific user (replace 'username'):

username ALL=(ALL) NOPASSWD: ALL

For an entire group (common in lab environments):

%wheel ALL=(ALL) NOPASSWD: ALL

Ubuntu typically uses the 'sudo' group. Enable passwordless access with:

%sudo ALL=(ALL:ALL) NOPASSWD: ALL

For security-conscious setups, limit passwordless access to specific commands:

username ALL=NOPASSWD: /usr/bin/apt, /usr/bin/systemctl

Allow shutdown commands without password (useful for lab PCs):

%labusers ALL=NOPASSWD: /sbin/shutdown, /sbin/reboot

After saving changes, verify with:

sudo -k  # Clear cached credentials
sudo -n true  # Should return successfully without password
  • Ensure users are in the specified groups (groups username)
  • Check for conflicting rules in /etc/sudoers.d/
  • Wildcards work but use carefully: NOPASSWD: /usr/bin/python*

While convenient, passwordless sudo should only be used in:

  • Single-user development machines
  • Air-gapped lab environments
  • Contained CI/CD systems

For production systems, consider timeout configurations instead: Defaults timestamp_timeout=30 (minutes between password prompts)


Passwordless sudo allows specified users to execute commands with root privileges without entering a password. This is particularly useful in:

  • Automation scripts
  • CI/CD pipelines
  • Trusted development environments
  • Training/lab setups

There are two primary ways to configure passwordless sudo:

Method 1: Editing sudoers File

The most reliable approach is modifying the sudoers file using visudo:

sudo visudo

Add this line for a specific user (replace 'username'):

username ALL=(ALL) NOPASSWD: ALL

Or for a group (e.g., wheel or sudo group):

%wheel ALL=(ALL) NOPASSWD: ALL

Method 2: Creating Sudoers.d File

For better management, create a separate file in /etc/sudoers.d/:

echo "username ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/passwordless-sudo
sudo chmod 440 /etc/sudoers.d/passwordless-sudo

For RHEL/CentOS/Fedora

Default admin group is usually 'wheel':

usermod -aG wheel username

For Ubuntu/Debian

Default admin group is 'sudo':

usermod -aG sudo username

While convenient, passwordless sudo should only be used in:

  • Single-user systems
  • Isolated lab environments
  • Controlled automation scenarios

For production systems, consider more granular permissions like:

username ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/systemctl

Test your configuration with:

sudo -k  # Clear cached credentials
sudo whoami  # Should return 'root' without password prompt

Common issues and solutions:

# If getting "username is not in the sudoers file"
usermod -aG sudo username  # Ubuntu/Debian
usermod -aG wheel username  # RHEL/CentOS

# If changes aren't taking effect
sudo -l  # Check effective permissions

For temporary access (e.g., training sessions):

echo "username ALL=(ALL) NOPASSWD: ALL, TIMEOUT=120" | sudo tee /etc/sudoers.d/temp-access

This grants 2 hours of passwordless access.