Terminal – Diagnosing why sudo is taking longer to respond

hangmacospermissionsudoterminal

I recently updated to macOS Sierra 10.12.4 Beta (16E144f) and it might be what is causing sudo to delay up to 10 minutes as it's the most recent change I recall since this problem occurred. I have never had to wait so long for a basic program and something is clearly wrong. The command eventually succeeds, but after waiting way too long.

I've been using this question as a reference. So far, I've tried adding my hostname to the end of the 127.0.0.1 line in /etc/hosts as well as. I checked /etc/resolv.conf and I did have some extra entries from when I was on a network that needed manual DNS entries, but I removed them and there has been no difference. I used the networksetup -setdnsservers command to restore the original values. Internet still works fine but still a very slow sudo.

I tried the logger 'test' command thinking it would write to /var/log/system.log, but it looks like it totally deleted that file although it was soon made anew.

I was hoping to use the strace command to see what was happening while sudo ran but that command is not available on OS X. Has anyone ran into this problem on this operating system before?

/var/log/system.log has the following messages that may be relevant. Again the command does eventually succeed as normal:

Feb  1 00:07:39 mycomputer com.apple.xpc.launchd[1] (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
Feb  1 00:07:56 mycomputer com.apple.xpc.launchd[1] (com.apple.quicklook[2355]): Endpoint has been activated through legacy launch(3) APIs. Please switch to XPC or bootstrap_check_in(): com.apple.quicklook
Feb  1 00:08:16 mycomputer System Preferences[1886]: I can not do what i want
Feb  1 00:11:23 mycomputer com.apple.xpc.launchd[1] (com.apple.opendirectoryd[2335]): Service exited with abnormal code: 70
Feb  1 00:12:07 mycomputer syslogd[54]: ASL Sender Statistics
Feb  1 00:16:35 mycomputer com.apple.xpc.launchd[1] (com.apple.opendirectoryd[2395]): Service exited with abnormal code: 70

Any help would be appreciated.

Best Answer

ErikMH's answer gave me the idea to first just try to revert the sudoers file, without reverting/upgrading my whole system again. So in short:

  1. Run this to get a root shell: sudo -s
  2. Make a copy of /private/etc/sudoers
  3. Run: cp /private/etc/sudoers\~orig /private/etc/sudoers
  4. Fix permissions by running: chmod 440 /private/etc/sudoers ; chown root:wheel /private/etc/sudoers
  5. Move any files in /private/etc/sudoers.d/ away from there
  6. Test out sudo in another terminal
  7. Don't forget to exit this shell to prevent inadvertently running commands as root when you don't mean to

Now running sudo should work again.

Next step is to check the differences between the old sudoers file (you copied away in step 2) and the current one and add those changes step by step back to /private/etc/sudoers or /private/etc/sudoers.d/, each time running a command using sudo to check if the change breaks it.

In my case, I had specified a nonexistent group in the sudoers file. Correcting that fixed my issue.