DEV Community

Play Button Pause Button
vinayak
vinayak

Posted on • Updated on

Configure passwordless sudo for a specific user in linux

In Linux, the sudo command allows users to execute administrative tasks with elevated privileges.

Image description

By default, when a user runs sudo, they are prompted to enter their own password to authenticate themselves. However, there are scenarios where you might want to configure passwordless sudo access for a specific user. This can be useful for automation scripts or specific administrative tasks. In this article, we will explore how to set up passwordless sudo for a specific user in Linux.

  • Edit the Sudoers File: The sudoers file contains the configuration for the sudo command. To edit this file, you need root or sudo privileges. Open a terminal and run the following command:
sudo visudo
Enter fullscreen mode Exit fullscreen mode
  • Configure Passwordless Sudo: Within the sudoers file, locate the section that grants sudo access to users. its look like
# User privilege specification
root    ALL=(ALL:ALL) ALL
Enter fullscreen mode Exit fullscreen mode

Paste your username with following command, to grant passwordless sudo access.

<your_username>    ALL=(ALL) NOPASSWD:ALL
Enter fullscreen mode Exit fullscreen mode

Replace "your_username" with the actual username of the user you want to grant passwordless sudo access to.
To get your username use following command :

echo $USER
Enter fullscreen mode Exit fullscreen mode

The NOPASSWD option allows the user to run any command with sudo without entering their password.

  • Test the Configuration:

Run a command that requires sudo privileges:

sudo ls
Enter fullscreen mode Exit fullscreen mode

If the configuration was successful, the command should execute without prompting for a password.

Top comments (5)

Collapse
 
spo0q profile image
spO0q πŸ’πŸŽƒ

I understand it's convenient, but it's not recommended. Besides, passwordless is a bit misleading, as the term usually indicates there's no password but still an authentication factor.

Here, you simply deactivate the password prompt.

Why use tag #security?

Collapse
 
itsvinayak profile image
vinayak

True, removing it

Collapse
 
spo0q profile image
spO0q πŸ’πŸŽƒ

thanks

Collapse
 
vsaulis profile image
Vladas Saulis

Is this documented feature?

Collapse
 
itsvinayak profile image
vinayak

yes, you can find the article at gfg : geeksforgeeks.org/configure-passwo...