adding myself to sudoer file

Status
Not open for further replies.
Joined
Jan 28, 2011
Messages
234
Reaction score
0
Points
16
So I edited my sudoer file as Administrator, added myself, then logged back into my own account - memyselfandi.
When I test my sudoer status by doing

mycomputer$ sudo echo "hello world"

I get a complaint ...

/private/etc/sudoers.d/sudoers:1:11: syntax error
<memyselfandi> ALL=(ALL) ALL
^


Um, what's wrong with what I edited into my sudoer file? What is this error?
FWIW, I'm then asked for the password, and once I give it, it does the echo properly.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,042
Reaction score
2,454
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
How did you edit the sudoers file? Did you do "sudo visudo" and then duplicate the root line and replace root with your username? Or did you edit the file in a different way?
 
Joined
Sep 30, 2007
Messages
9,962
Reaction score
1,236
Points
113
Location
The Republic of Neptune
Your Mac's Specs
2019 iMac 27"; 2020 M1 MacBook Air; macOS up-to-date... always.
So I edited my sudoer file as Administrator, added myself, then logged back into my own account - memyselfandi.
When I test my sudoer status by doing

mycomputer$ sudo echo "hello world"

I get a complaint ...

/private/etc/sudoers.d/sudoers:1:11: syntax error
<memyselfandi> ALL=(ALL) ALL
^


Um, what's wrong with what I edited into my sudoer file? What is this error?
FWIW, I'm then asked for the password, and once I give it, it does the echo properly.

Since we don't know HOW you did this, we couldn't tell you what you did wrong. Here's a guide on how to do it:

And another:

 
  • Like
Reactions: IWT
OP
D
Joined
Jan 28, 2011
Messages
234
Reaction score
0
Points
16
Yes, I did "sudo visudo" and just duplicated the root line (with the tab after the account name), but with my own account name. Those two lines are identical except for the account name. So yes, you know HOW I did this, and it just took me a few hours to answer. Unlike what it quotes in that syntax error, the actual line I added was
memyselfandi ALL=(ALL) ALL without the brackets. But that should have been obvious.

Oh, and I already have all the web instructions that you pointed to. As far as I can tell, I did exactly what they told me to do.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,042
Reaction score
2,454
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
The sudoers file is very finicky thus you have to edit with the 'visudo' command and ensure that you follow the style of the other content in there.

I just modified my file to be the following
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
<username> ALL = (ALL) ALL
%admin ALL = (ALL) ALL

And I can now sudo without the need for my password. I do notice that you don't have spaces between "ALL=(ALL)" like I do, so ensure that your file looks like something like mine.
 
OP
D
Joined
Jan 28, 2011
Messages
234
Reaction score
0
Points
16
Thanks. As I said, I duplicated the line for root. So the spacing is identical (with a tab after username). No reason why if it works for root, it shouldn't work for me. That's what I'm asking about here.

This below is exactly what is in that section (copied from the visudo display)

# root and users in group wheel can run anything on any machine as any user root ALL = (ALL) ALL %admin ALL = (ALL) ALL memyselfandi ALL = (ALL) ALL

So the issue is, where is the syntax error in all this?

In fact, I get that error even when visudo is first invoked.

mycomputer$ sudo visudo /private/etc/sudoers.d/sudoers:1:11: syntax error <memyselfandi> ALL=(ALL) ALL ^ Password:
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,042
Reaction score
2,454
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Remove the line you added, save the file and go back into visudo to ensure that the error disappears and re-add the line to see what happens.
 
OP
D
Joined
Jan 28, 2011
Messages
234
Reaction score
0
Points
16
Hmmm. The VERY funny thing is that once I do that, and remove the line I added, I get PRECISELY THE SAME SYNTAX ERROR. That is, if you go into visudo, and look at the file, that added line is completely gone, but somehow the sudoer file has gotten cached somewhere!
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,042
Reaction score
2,454
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
So just removing the line gives you that error? If so, there is an error in the file itself. Check line #11 of the file to see what it says.
 
OP
D
Joined
Jan 28, 2011
Messages
234
Reaction score
0
Points
16
Line 11 is the first line in the sequence
Defaults env_reset Defaults env_keep += "BLOCKSIZE" Defaults env_keep += "COLORFGBG COLORTERM" Defaults env_keep += "__CF_USER_TEXT_ENCODING"
 
Joined
Sep 30, 2007
Messages
9,962
Reaction score
1,236
Points
113
Location
The Republic of Neptune
Your Mac's Specs
2019 iMac 27"; 2020 M1 MacBook Air; macOS up-to-date... always.
Yes, I did "sudo visudo" and just duplicated the root line (with the tab after the account name), but with my own account name. Those two lines are identical except for the account name. So yes, you know HOW I did this, and it just took me a few hours to answer. Unlike what it quotes in that syntax error, the actual line I added was
memyselfandi ALL=(ALL) ALL without the brackets. But that should have been obvious.

NOTHING is obvious when typos are a potential thing, not to mention skill levels for this sort of thing on the part of the user are an unknown. We periodically get people in here who muck about with the command line not know what they are doing. What was seemingly obvious was you did something wrong, so it was back to basics.
 
OP
D
Joined
Jan 28, 2011
Messages
234
Reaction score
0
Points
16
Lifeisabeach, do you specialize in not being constructive? Time to bow out.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,042
Reaction score
2,454
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
And with that we're done.
 
Status
Not open for further replies.

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top