Sample Header Ad - 728x90

sudoers file change not working?

0 votes
2 answers
6340 views
I'm in Ubuntu 18.04LTS and I want to change the sudoers file to execute sudo shutdown -h now without the need of password (for my_username). The steps I take were: With my user my_username open terminal: sudo visudo The line I added: my_username ALL=(ALL) NOPASSWD: /sbin/shutdown Where there is only one tab in the first part (between user and ALL) and the rest are spaces. The user is the one it appears after id in terminal. After that, just in case I restart the system, and type sudo shutdown -h now but it keeps asking for password. What I'm doing wrong? -----EDIT------ Ok, I didn't know that the order in which you add the lines were important, so as asked I added my full file (it's a very simple sudoers config).
#
# 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

# 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:
my_username	ALL=(ALL) NOPASSWD: /sbin/shutdown
#includedir /etc/sudoers.d
This way it works perfectly for me. The problem was that I added the line after root line.
Asked by Aurelie Navir (137 rep)
May 25, 2020, 11:07 AM
Last activity: May 25, 2020, 11:58 AM