Editing the sudoers file on Mac or Linux when you

2019-08-14 04:57发布

问题:

I'm trying to install something on my MacOS (or Linux) system and I don't have permission because I'm not the admin. So I tried using sudo and it says that I'm not in /etc/sudoers file. I've tried editing the sudoers file but it won't let me, so I "googled" it. Everybody says to use visudo to edit the file. The problem is, it won't even let me use visudo! When I type "visudo" it just says

visudo: /etc/sudoers: Permission denied

Would appreciate some help. Thanks in advance!

EDIT: I tried switching users and then editing the sudoers file but still didn't work

回答1:

You need to be root (or have rootprivileges) in order to use the visudo command and edit the sudoers file



回答2:

If u messed up your sudoers file.You'll need to:

  • Reboot into recovery mode (hit escape during boot, choose the recovery mode option on the grub screen)
  • Choose the 'Enable networking' option (if you don't your filesystem will be mounted as read-only. who knew)
  • Chosee the 'Drop to root shell' option
  • run visudo, fix your file
  • Reboot with normal grub option

source :- http://mario.net.au/content/recover-etcsudoers-ubuntu-1204



回答3:

You have to be root or use sudo to edit the sudoers file.

sudo visudo


回答4:

I am new to mac. Very annoyed by the time=0 for sudoer (you havew to type the password every time you use sudo). I want to increase this value to a reasonable number: timestamp_timeout=30. After adding the above line to the /etc/sudoers file, I could not login as su anymore because the parser fails to read the sudoers file. This posting is to document how I fix this problem.

1. Restart your mac
2. Hold on to Command-R two keys until you see the progress bar.
3. Start a new terminal, this terminal will be the root terminal
4. Edit the invalid sudoers file.  Note this file is not in /etc/sudoers when you loggedin in as root

The full path is: /Volumes/Macintosh HD/etc restart then you are happy again.

This method will also apply to users who are not in the sudoers list and want to add themselves to the list.

Note: if you could not find the sudoers file as root use find:

find / -name sudoers