1

When I try to enter commands into the terminal I get this message "myusername is not in the sudoers file. This incident will be reported." It started when I tried to edit my host-file. What do I do to fix this? I want to spoof my MAC address. I have the newest version of OS X. myusername is not actually my real username.

1
  • Just out of curiosity, is this your Mac computer or is this one from your workplace (or similar) that was issued to you? I am also not clear as to why your username isn't your real username. Can you elaborate?
    – Allan
    Commented Aug 13, 2016 at 22:32

2 Answers 2

1

Probably you aren't logged in as admin user or the admin entry in the sudoers file was removed accidentally.

So either log in as user with admin privileges or modify the sudoers file. The sudoers file located in /etc should show the following entries beginning at line 55:

##
## User privilege specification
##
root ALL=(ALL) ALL
%admin  ALL=(ALL) ALL

The last line denotes the ability of all admin users to act with root permissions by prepending sudo ... in the command line – e.g. to edit the hosts file with sudo nano /etc/hosts. Only the root user would be able to enter just nano /etc/hosts and successfully edit the file.

The file /etc/sudoers can only be read or modified with root privileges!


If you are logged in as an arbitrary admin user you have to check the file /etc/sudoers. Since your admin vanished from the sudoers file you have to reboot to Recovery Mode and check/edit the file.

In Recovery Mode open in the menubar Utilities > Terminal. Enter mount to get all mounted volumes:

/dev/disk2s1 on / (hfs, local, read-only)
devfs on /dev (devfs, local, nobrowse)
/dev/disk3 on /private/var/log (hfs, local, union, nobrowse)
/dev/disk4 on /Volumes (hfs, local, union, nobrowse)
/dev/disk5 on /private/var/tmp (hfs, local, union, nobrowse)
/dev/disk6 on /private/var/run (hfs, local, union, nobrowse)
/dev/disk7 on /System/Installation (hfs, local, union, nobrowse)
/dev/disk8 on /private/var/db (hfs, local, union, nobrowse)
/dev/disk9 on /private/var/folders (hfs, local, union, nobrowse)
/dev/disk10 on /private/var/root/Library (hfs, local, union, nobrowse)
/dev/disk12 on /Library/Preferences (hfs, local, union, nobrowse)
/dev/disk13 on /Library/Preferences/SystemConfiguration (hfs, local, union, nobrowse)
/dev/disk14 on /Library/Keychains (hfs, local, union, nobrowse)
/dev/disk15 on /private/var/tmp/RecoveryTemp (hfs, local, union, nobrowse)
/dev/disk0s2 on /Volumes/Data (hfs, local, journaled)
/dev/disk1s2 on /Volumes/Macintosh HD (hfs, local, journaled)
/dev/disk1s3 on /Volumes/Image Volume (hfs, local, read-only, journaled)

Search for the name of your main volume - usually it's related to disk0s1, disk1 or disk2 (in my example it's Macintosh HD: /dev/disk1s2).

Then enter:

/Volumes/volume_name/usr/sbin/visudo /Volumes/volume_name/etc/suoders

In my example that's:

/Volumes/Macintosh\ HD/usr/sbin/visudo /Volumes/Macintosh\ HD/etc/suoders

and modify the file according to your needs (i.e add the line %admin ALL=(ALL) ALL if it's gone). You have to escape spaces in the volume's name with a \!


BTW “username is not in the sudoers file. This incident will be reported.” might have the consequence that Santa Claus will evade your home next christmas, except you have launched some counter-measures in advance – like securing your Mac with a firewall.

1
0

My case is very wierd. I post it here in case anyone face the same problem. And if anyone knows why please tell me :)

In my case, one day it suddenly reports "username is not in the sudoers file. This incident will be reported." when sudo things, while I have not done anything special and it worked perfectly before.

The solution is, go to settings - users and groups. Then tap the "tap the lock button to modify things" button and enter password. Then suddenly sudo can be used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .