The sudo command in Linux allows users to run certain commands as another user, preferably as root. Having sudo access allows regular users to perform tasks that otherwise require elevated permissions.

However, sudo requires users to enter their passwords for every new session. This can prove cumbersome for regular tasks like system maintenance. Luckily, you can easily use the sudo command without passwords.

Configure sudo Without Password

The sudoers file in Linux allows admins to manage usage rights for different users. You can grant additional permissions to regular users by adding them to the sudoers list. We can also configure sudo usage without any passwords by tweaking this file.

Follow the below steps to prevent sudo from asking for passwords ever again. Make sure to switch to the root user first.

Step 1: Backup the Sudoers File

You need to back up the sudoers file before modifying it. Run the following command in your terminal to create a copy of the sudoers list.

        cp /etc/sudoers /etc/sudoers.old
    
backup sudoers list in Linux

Step 2: Open the Sudoers File

Use the visudo command for safely opening the sudoers file. It adds some safeguards against unwanted errors and validates the syntax.

        visudo
    
visudo command in Linux

Step 3: Modify the Sudoers File

Once you've opened the sudoers list, go to the bottom of the file and add the following line.

        rubaiat ALL=(ALL) NOPASSWD: ALL
    

Replace rubaiat with your username to stop Linux from asking the sudo password ever again. You can also grant sudo without password access to a different user by using their username instead of yours.

configure sudo to stop asking for password

Step 4: Save and Exit Visudo

You need to save and exit visudo after adding the above line. If you have configured visudo to use the Vim editor on your machine, use the below command to save and exit Vim.

        :wq
    

Press Ctrl + X if visudo is using the nano text editor. You can now check whether everything went as expected by issuing a command that require superuser permissions.

using sudo without password

Using sudo Without Passwords in Linux

You'll gain sudo access without a password once you complete the above steps. However, using sudo without passwords may prove to be a security threat if you're using it for untrusted scripts. Plus, anyone with physical access to your machine can perform system operations without authorization.

Since the risk of compromised credentials is continuously rising in the workplace, you should not use sudo without passwords in your office.