I think I made a mistake by editing /etc/hosts within sublime text, because immediately afterward I was unable to run "sudo xxx". It would ask for a password, and then never resolve once I'd typed it in.
I tried to edit /etc/hosts, but it always required sudo, which never resolved, so that didn't work. In the end I just deleted the file, but I'm stuck now with not being able to recreate it without access to sudo. Any ideas?
Best Answer
The file /etc/hosts is in no way related to the ability to run sudo. You probably hosed your sudoers file in a previous step.
To solve your problem boot to Recovery Mode and open Terminal in the menubar > Utilities.
df
to get the name of your main system volume.Change your working directory to /Volumes//etc:
Copy the spare files hosts~orig and sudoers~orig (or with similar names which may exist as "backup" in /etc by default - check this with
ls
!):If they don't exist create the hosts file and and check your sudoers file:
The content of the default hosts file is.
The POSIX permissions are root:wheel 644. Modify this with
chown
andchmod
if necessary./Volumes//usr/bin/nano /Volumes//etc/sudoers
A minimal (to type less!) working sudoers file looks like this:
The POSIX permissions are root:wheel 440. Modify this with
chown
andchmod
if necessary.Reboot your Mac by entering:
This can also be done in single-user-mode after mounting the root volume rw.
After regaining the ability to run sudo, either extract it from the macOS installer app with Pacifist or from a backup or modify it yourself with
visuso
. The default content is: