In a Linux system, to set up sudo passwordless access, follow these steps:
Open the sudoers file as an administrator: In the terminal, enter the command sudo visudo
. This command will open the sudoers file in a safe manner, ensuring the file syntax is correct and preventing system issues due to incorrect edits.
Add the passwordless rule: In the opened sudoers file, find an appropriate location and add a line of rule. If you want the user named username to execute all sudo commands without a password, you can add:
username <span>ALL=(ALL) NOPASSWD:ALL</span>
If you want all users belonging to the sudo group to execute all sudo commands without a password, then add:
%sudo <span>ALL=(ALL) NOPASSWD:ALL</span>
Be sure to replace username with the actual username.
Save and exit: In the vi editor, press the Esc key, then type :wq
, and press Enter to save and exit.
Test the configuration: Reopen the terminal and run a command that requires sudo privileges, such as sudo apt update
. If the configuration is correct, the system will execute the command directly without prompting for a password.