Score:0

Granting sudo access without prompting for password

cn flag

I have added a username to the sudoer file, but as you can see below, when I run sudo ls I have to enter the password. How can I fix that in order to run passwordless sudo commands for the test user.

test@ubuntu:~$ sudo ls
[sudo] password for test:
test@ubuntu:~$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
test    ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
test@ubuntu:~$

UPDATE:

After setting NOPASSWD:, still I have to enter the password. See below:

test@ubuntu:~$ sudo ls
[sudo] password for test:
test@ubuntu:~$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
test    ALL=(ALL:ALL) NOPASSWD: ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
test@ubuntu:~$
Score:1
us flag

You can use test ALL=(ALL) NOPASSWD: ALL for giving user test access without password

Note that if test user is in admin or sudo group, it's settings would be overridden in groups settings. To avoid that, write your user settings after group settings:

%admin ALL=(ALL) ALL
%sudo   ALL=(ALL:ALL) ALL
...
test    ALL=(ALL:ALL) NOPASSWD: ALL
cn flag
It doesn't work. Please see the updated post.
Amin avatar
us flag
Is test user in admin or sudo group ? @mahmood
Amin avatar
us flag
I've updated my answer @mahmood
cn flag
OK I found that `%sudo ALL=(ALL) NOPASSWD: ALL` fixes the problem. Thanks for th hints.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.