Admin password not working for sudo

mojavepasswordpermissionsudoterminal

I've been trying to run this command in the terminal:

$  sudo rm -ri ~/.Trash

However after being prompted to type in my password (which I believe it needs to be the admin's password) and after typing it, it just says: "Sorry, try again".

I am logged onto the only user account this Mac has, which has admin privileges. I've tried repairing disk permissions as well as reinstalling the OS (Mojave), but with no success.

Not sure what to do anymore! Can someone help me out with this one?

UDPATE #1

When I run $ sudo -l I get this:

Matching Defaults entries for diogopires on MacBook-Pro-DI:
    env_reset, env_keep+=BLOCKSIZE, env_keep+="COLORFGBG COLORTERM",
    env_keep+=__CF_USER_TEXT_ENCODING, env_keep+="CHARSET LANG LANGUAGE LC_ALL
    LC_COLLATE LC_CTYPE", env_keep+="LC_MESSAGES LC_MONETARY LC_NUMERIC
    LC_TIME", env_keep+="LINES COLUMNS", env_keep+=LSCOLORS,
    env_keep+=SSH_AUTH_SOCK, env_keep+=TZ, env_keep+="DISPLAY XAUTHORIZATION
    XAUTHORITY", env_keep+="EDITOR VISUAL", env_keep+="HOME MAIL",
    lecture_file=/etc/sudo_lecture, targetpw

User diogopires may run the following commands on MacBook-Pro-DI:
    (ALL) ALL
    (ALL) ALL

And if I try and run visudo or sudo -u diogopires visudo, I get:

visudo: /etc/sudoers.tmp: Permission denied

UDPATE #2

Furthermore, to check group membership, I got:

$ id -a | grep -o '[0-9]\+(admin)'
80(admin)

UDPATE #3

Upon running set -x, I ran and got:

$ sudo -l
+ sudo -l
Password:
Matching Defaults entries for diogopires on MacBook-Pro-DI:
    env_reset, env_keep+=BLOCKSIZE, env_keep+="COLORFGBG COLORTERM",
    env_keep+=__CF_USER_TEXT_ENCODING, env_keep+="CHARSET LANG LANGUAGE LC_ALL
    LC_COLLATE LC_CTYPE", env_keep+="LC_MESSAGES LC_MONETARY LC_NUMERIC
    LC_TIME", env_keep+="LINES COLUMNS", env_keep+=LSCOLORS,
    env_keep+=SSH_AUTH_SOCK, env_keep+=TZ, env_keep+="DISPLAY XAUTHORIZATION
    XAUTHORITY", env_keep+="EDITOR VISUAL", env_keep+="HOME MAIL",
    lecture_file=/etc/sudo_lecture, targetpw

User diogopires may run the following commands on MacBook-Pro-DI:
    (ALL) ALL
    (ALL) ALL
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i < 17 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 17 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i < 17 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 17 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 17 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 17 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 17 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 17 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i < 17 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 17 ))
++ ch=o
++ [[ o =~ [/._~A-Za-z0-9-] ]]
++ url_path+=o
++ (( ++i ))
++ (( i < 17 ))
++ ch=g
++ [[ g =~ [/._~A-Za-z0-9-] ]]
++ url_path+=g
++ (( ++i ))
++ (( i < 17 ))
++ ch=o
++ [[ o =~ [/._~A-Za-z0-9-] ]]
++ url_path+=o
++ (( ++i ))
++ (( i < 17 ))
++ ch=p
++ [[ p =~ [/._~A-Za-z0-9-] ]]
++ url_path+=p
++ (( ++i ))
++ (( i < 17 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 17 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 17 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 17 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 17 ))
++ printf '\e]7;%s\a' file://MacBook-Pro-DI.local/Users/diogopires

And afterwards, I ran and got:

$ sudo ls
+ sudo ls
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
sudo: 3 incorrect password attempts
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i < 17 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 17 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i < 17 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 17 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 17 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 17 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 17 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 17 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i < 17 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 17 ))
++ ch=o
++ [[ o =~ [/._~A-Za-z0-9-] ]]
++ url_path+=o
++ (( ++i ))
++ (( i < 17 ))
++ ch=g
++ [[ g =~ [/._~A-Za-z0-9-] ]]
++ url_path+=g
++ (( ++i ))
++ (( i < 17 ))
++ ch=o
++ [[ o =~ [/._~A-Za-z0-9-] ]]
++ url_path+=o
++ (( ++i ))
++ (( i < 17 ))
++ ch=p
++ [[ p =~ [/._~A-Za-z0-9-] ]]
++ url_path+=p
++ (( ++i ))
++ (( i < 17 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 17 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 17 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 17 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 17 ))
++ printf '\e]7;%s\a' file://MacBook-Pro-DI.local/Users/diogopires

Best Answer

For whatever reason you seem to have the targetpw option set. From man sudoers:

targetpw   If set, sudo will prompt for the password of the user specified by the -u
           option (defaults to root) instead of the password of the invoking user when
           running a command or editing a file.  Note that this flag precludes the use
           of a uid not listed in the passwd database as an argument to the -u option.
           This flag is off by default.

So you can do things like sudo -u diogopires ls by entering your own password, but you can't run sudo -u diogopires visudo because this would run visudo as diogopires (and not as root as it should).

So, to fix this

  • Boot into single user mode by pressing Cmd-S on startup
  • Run mount -uw /
  • Use visudo (without sudo) to remove the option
  • Type Ctrl-D or run reboot to reboot