Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 18374  / 3 Years ago, sat, june 5, 2021, 4:30:15

Running a fresh install of Ubuntu server 16.04.1, I tried to add a file in /etc/sudoers.d/ to give one user root privileges for a certain command.



I added the file /etc/sudoers.d/servicetest with the following content:



servicetest ALL = (root) NOPASSWD: /bin/systemctl status *


The file /etc/sudoers is left untouched. It contains #includedir /etc/sudoers.d as the last line.
This setup is unfortunately not working, when executing an appropriate command with sudo as the user servicetest, I am still asked for the password. However, if I move the content of the file /etc/sudoers.d/servicetest to the end of /etc/sudoers, everything is working as expected.



What could be the cause of this issue? How can I get files in /etc/sudoers.d/ working?


More From » 16.04

 Answers
0

The problem was not, as answered by IanC, caused by the file permissions (sudo happily accepts a file owned by root:root 0644, as I can confirm now, although it should of course be root:root 0440 for security reasons!), but by a newline at the end of the file which was preceded by a windows-style line ending (
).



sudo only accepts
as line endings.


[#13215] Sunday, June 6, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ncharm

Total Points: 255
Total Questions: 105
Total Answers: 118

Location: Virgin Islands (U.S.)
Member since Sat, May 6, 2023
1 Year ago
;