Terminal commands getting error messages.

Joined
Oct 14, 2010
Messages
28
Reaction score
1
Points
3
Your Mac's Specs
MacBook Air 10.7, iMac 21" 10.7
I have been trying to edit the sudoers file for some time now, and have been getting error messages on multiple occurrences. I run "su root" first to become root user, as "visudo" has to be run that way. I type the Administrator password for my computer, and "su: sorry" comes up. I assumed maybe I had type it wrong, but the problem repeatedly came up. The password for logging in to the Admin account works fine, but not in Terminal. I tried going in to the Admin account and running "su root", but the same thing occurred.

I also noticed when I run a sudo command I get an error message saying "sudo: /etc/sudoers is mode 0777, should be 0440
Segmentation fault"
I'm not particularly sure what this is.

Any help would be greatly appreciated.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
sudo visudo works fine for me. Have you changed the permissions on the /etc/sudoers file as those permissions listed (777) give everyone read, write and execute permissions?
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
It appears to me that the permission of the sudoers file was changed to 777. Also it appears that someone tried to execute (run) the sudoers file by doing sudo /etc/sudoers, instead of sudo visudo as suggested. As for the su root, the root account has been disabled, so you can not log in to it.

I don't believe you need to edit the sudoers file, because I think you should be able to anything that you want to do by doing:

sudo command
 
OP
S
Joined
Oct 14, 2010
Messages
28
Reaction score
1
Points
3
Your Mac's Specs
MacBook Air 10.7, iMac 21" 10.7
sudo visudo works fine for me. Have you changed the permissions on the /etc/sudoers file as those permissions listed (777) give everyone read, write and execute permissions?

Hmm... I tried changing the permissions but still no luck. I get no error messages when doing that, but when visudo is run the same error occurs. (visudo: /etc/sudoers.tmp: Permission denied) I had read that "etc/sudoers.tmp" is a file that visudo creates when modifying the sudoers file, and normally deletes after a successful run but I have never ran visudo until now.
 
Joined
Jul 2, 2007
Messages
3,494
Reaction score
204
Points
63
Location
Going Galt...
Your Mac's Specs
MacBookAir5,2:10.13.6-iMac18,3:10.13.6-iPhone9,3:11.4.1
On my system I use the command:
sudo visudo
I don't specify the file name or path

Example:
MacGyver:~ username$ visudo
visudo: /etc/sudoers: Permission denied
visudo: /etc/sudoers: Permission denied
MacGyver:~ username$ sudo visudo
Password:
visudo: /etc/sudoers.tmp unchanged
MacGyver:~ username$ sudo visudo /etc/sudoers
usage: visudo [-c] [-q] [-s] [-V] [-f sudoers]
MacGyver:~ username$ cd /etc
MacGyver:etc username$ ls -la | grep sudoers
-r--r----- 1 root wheel 1242 Oct 20 19:22 sudoers

You might check to make sure your permissions are the same and if not, use the command:
sudo chmod 0440 /etc/sudoers
sudo chown root:wheel /etc/sudoers
 
OP
S
Joined
Oct 14, 2010
Messages
28
Reaction score
1
Points
3
Your Mac's Specs
MacBook Air 10.7, iMac 21" 10.7
Thanks for the input, this is where I'm at. I tried running "sudovisudo" but found no luck. Any command that uses "sudo" falls back on the error message I have constantly repeating: "computername:~ username$ sudo chmod 0440 /etc/sudoers
sudo: /etc/sudoers is mode 0777, should be 0440
Segmentation fault"

Running any sudo command causes this problem.

I'm not sure how to check if the permissions are the same, so I just did "sudo chmod 0440 /etc/sudoers" to make sure it was, but I got error "sudo: /etc/sudoers is mode 0777, should be 0440
Segmentation fault", the same as always when using "sudo".
Since it appears that I have in some way been "locked out" of running sudo commands, I tried doing that last command without the sudo part but the operation was not permitted, as expected.

Running "sudo chown root:wheel /etc/sudoers" doesn't work because of the same error message, but "chown root:wheel /etc/sudoers" does, or appears to work.
 
Joined
Jul 2, 2007
Messages
3,494
Reaction score
204
Points
63
Location
Going Galt...
Your Mac's Specs
MacBookAir5,2:10.13.6-iMac18,3:10.13.6-iPhone9,3:11.4.1
You may need to enable actual su access to the root user account to correct it.

Enable root account in Snow Leopard | Snow Leopard Tips

See if you can run the chmod 0440 command after you enable root. The commands are the same but without the "sudo" part at the beginning...

chmod 0440 /etc/sudoers
chown root:wheel /etc/sudoers

Then disable root access, log off, and then back on again to check the results.
 
OP
S
Joined
Oct 14, 2010
Messages
28
Reaction score
1
Points
3
Your Mac's Specs
MacBook Air 10.7, iMac 21" 10.7
Ok, so I did as the link you showed me said and enabled the root user - no problems there. But when I went in to Terminal and ran "su root" it stillsays that the password is wrong. It wasn't mistyped, I made sure of that, and I reset the root password many times, checking for errors. The commands had the same outcomes as before, (errors).
Maybe I deleted a system file or corrupted something important? It seems that I'm the only one to ever have a problem like this.... Can you think of any other reasons it possibly couldn't be working? Thanks for the help.
 
OP
S
Joined
Oct 14, 2010
Messages
28
Reaction score
1
Points
3
Your Mac's Specs
MacBook Air 10.7, iMac 21" 10.7
Oops... sorry. It appears I have figured it out. Apparently I was not being allowed to "su" root because of the current privileges of my account. Once I changed it to admin, I was able to su root and run the commands that you gave me without sudo. Then I logged out, logged back in and ran visudo, this time successfully eiting the sudoers file. Thanks a lot :).
 
Joined
Jul 2, 2007
Messages
3,494
Reaction score
204
Points
63
Location
Going Galt...
Your Mac's Specs
MacBookAir5,2:10.13.6-iMac18,3:10.13.6-iPhone9,3:11.4.1
I never thought to ask whether your user was an Admin user. Good catch!
 

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