LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-14-2017, 05:21 AM   #1
tranphat
Member
 
Registered: Dec 2013
Posts: 86

Rep: Reputation: Disabled
strang comment for /etc/sudoers.d


Hi all,

I find that in my system, the information about the granting root privilege to ordinary users are put in the /etc/sudoers.d/ folder.

But when I read the /etc/sudoers file, I found this:

#includedir /etc/sudoers.d

so, the # sign here does not mean "comment out", right?

Please advise. It's so strang to me.
 
Old 02-14-2017, 05:39 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
The penultimate authority there is the manual page for sudoers. It is second only to the source code.

Code:
man sudoers
It states:

Code:
   Including other files from within sudoers
     It is possible to include other sudoers files from within the sudoers
     file currently being parsed using the #include and #includedir direc‐
     tives.

     This can be used, for ...
So what you see is the correct syntax for including other configuration files into sudoers. However, it does not explain why such a syntax is used or the etymology of such a syntax which might be your real question.

However, it does mean that you can put additional files in /etc/sudoers.d/ and, as long as they conform to sudoers syntax, they will be used. If they do not conform to the syntax, they will break sudo for you. The advantage of such files is that you can add and remove configurations in an automated manner, if so needed, without needing to parse or search the main configuration file.
 
1 members found this post helpful.
Old 02-14-2017, 05:57 AM   #3
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,574
Blog Entries: 19

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
It's commented out because, if it was active and there were actually no suitable files in sudoers.d, sudo would stop working! I remember a post here from someone who uncommented this line as an experiment; he couldn't use sudo afterwards and, as he was using a distro of the Ubuntu family, he couldn't easily correct his mistake either. To either correct sudoers or create files in sudoers.d, he needed sudo access...

"You can" in this context means you can in theory, not that you can with the default sudoers configuration.
 
Old 02-14-2017, 06:00 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by hazel View Post
I remember a post here from someone who uncommented [sic] this line as an experiment; he couldn't use sudo afterwards...
That would be incorrect syntax to remove the pound sign from that directive. Getting locked out will happen with any other syntax error sudoers as well. In this particular case, the #include is the actual syntax, same for #includedir there.
 
Old 02-14-2017, 06:15 AM   #5
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
sudoers already uses a lot of special characters, it could be that '#' was unusued and needed as prefix to separate it from other configuration, so that sudo isn't trying to assign things for the user include.
 
Old 02-14-2017, 08:30 PM   #6
tranphat
Member
 
Registered: Dec 2013
Posts: 86

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
The penultimate authority there is the manual page for sudoers. It is second only to the source code.

Code:
man sudoers
It states:

Code:
   Including other files from within sudoers
     It is possible to include other sudoers files from within the sudoers
     file currently being parsed using the #include and #includedir direc‐
     tives.

     This can be used, for ...
So what you see is the correct syntax for including other configuration files into sudoers. However, it does not explain why such a syntax is used or the etymology of such a syntax which might be your real question.

However, it does mean that you can put additional files in /etc/sudoers.d/ and, as long as they conform to sudoers syntax, they will be used. If they do not conform to the syntax, they will break sudo for you. The advantage of such files is that you can add and remove configurations in an automated manner, if so needed, without needing to parse or search the main configuration file.
thank you for explaining. So in this case, it is the real syntax of sudoers file. Now I fully understand.
 
Old 02-14-2017, 08:33 PM   #7
tranphat
Member
 
Registered: Dec 2013
Posts: 86

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
sudoers already uses a lot of special characters, it could be that '#' was unusued and needed as prefix to separate it from other configuration, so that sudo isn't trying to assign things for the user include.
Can you please say a little bit more detail? Still not get your point for the sentence: it could be that '#' was ....."
 
Old 02-15-2017, 04:09 AM   #8
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
I am saying that they probably needed a special character which could not be confused with being a group, a username or a command and given the normal usage of # as a comment, it could not be used in any.
 
Old 02-15-2017, 07:08 AM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by tranphat View Post
so, the # sign here does not mean "comment out", right?
Please advise. It's so strang to me.
Incorrect. It mean you don't know what #comments are

The file is literally littered with comments.
https://gist.github.com/90f447357610...4d7e5fd43b950a
 
Old 02-15-2017, 07:15 AM   #10
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by Habitual View Post
Incorrect. It mean you don't know what #comments are

The file is literally littered with comments.
https://gist.github.com/90f447357610...4d7e5fd43b950a
Err, it also says "# does not mean comment" in regards to the lines the OP is talking about, Which are #include and #includedir, which are in fact, not comments despite appearing like them.
 
Old 02-15-2017, 08:46 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by tranphat View Post
Hi all,

I find that in my system, the information about the granting root privilege to ordinary users are put in the /etc/sudoers.d/ folder.

But when I read the /etc/sudoers file, I found this:

#includedir /etc/sudoers.d

so, the # sign here does not mean "comment out", right?

Please advise. It's so strang to me.
Does not your sudoer file have the included lines before that one line in question in your file?
Quote:
## Read drop-in files from /etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /etc/sudoers.d
that is an include command simular to a c file
Code:
#include <stdio.h>

Last edited by BW-userx; 02-15-2017 at 08:48 AM.
 
Old 02-15-2017, 10:16 AM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
Err, it also says "# does not mean comment" in regards to the lines the OP is talking about, Which are #include and #includedir, which are in fact, not comments despite appearing like them.
I give up.
"commented directives"?
 
Old 02-15-2017, 10:22 AM   #13
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
It should probably be mentioned that using 'visudo' is a good idea. It should catch any of your mistakes and keep you from writing a bad config. Don't edit sudoers by hand.
 
Old 02-16-2017, 09:32 PM   #14
tranphat
Member
 
Registered: Dec 2013
Posts: 86

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
Does not your sudoer file have the included lines before that one line in question in your file?


that is an include command simular to a c file
Code:
#include <stdio.h>
Hi, yes, it's my fault. I did not read carefully the instruction.
But by any way, it also surprises me, when # is usually used with meaning: "comment line".
 
Old 02-17-2017, 08:38 AM   #15
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by tranphat View Post
Hi, yes, it's my fault. I did not read carefully the instruction.
But by any way, it also surprises me, when # is usually used with meaning: "comment line".
yeah it threw me a little when I first seen that in sudoers file then read that line above it saying, ## (the '#' here does not indicate a comment), so I took its word for it and moved on.

I didn't put any reasoning or logic to it until this post showed up.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strang Yum error skoda Linux - Newbie 6 06-04-2014 01:13 PM
strang gtk-vnc behavior in -current zakame Slackware 2 04-29-2013 11:07 AM
[SOLVED] User not in sudoers: How to add user? Permtion Denied for sudoers file esgol Linux - Newbie 3 07-13-2012 07:44 AM
Fedora /etc/sudoers file and sudoers.d directory davejjj Linux - Newbie 2 10-21-2011 06:19 PM
I deleted /etc/sudoers and creates a new file call sudoers but now it doesnt for visu abefroman Linux - Software 1 11-10-2005 05:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration