How to Allow a Wheel User to Switch to Root Without a Password in Linux
Introduction
By default, switching to the root user using su - requires the root password. In environments where trusted administrators require frequent root access, Linux allows you to configure passwordless root access either through the wheel group or by using sudo.
Prerequisites
Before you begin, ensure you have:
- Root or administrative access to the server
- A Linux system with PAM support
- A user account to grant privileged access
Implementation
Method 1: Configure the Wheel Group
Step 1: Create a User
useradd test passwd test
Step 2: Add the User to the Wheel Group
usermod -aG wheel test
Step 3: Update the PAM Configuration
Edit the PAM configuration file:
vi /etc/pam.d/su
Uncomment the following line:
auth sufficient pam_wheel.so trust use_uid
On some older Linux distributions, the entry may appear as:
auth sufficient /lib/security/$ISA/pam_wheel.so trust use_uid
Save the file and exit.
Step 4: Test the Configuration
Log in as the user and execute:
su -
The user should now switch to the root account without being prompted for the root password.
Method 2: Configure Passwordless sudo
Edit the sudoers file:
visudo
Add the following entry:
test ALL=(ALL) NOPASSWD:ALL
Save the file and exit.
The user can now become root using:
sudo su -
Conclusion
You can allow a trusted user to become the root user without entering a password using either the wheel group with PAM or sudo with the NOPASSWD option. While both methods achieve the same result, sudo is generally the preferred approach as it provides better control and auditing of privileged access.
