2

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
2

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
1

Idea #1 - Using your password

The entire purpose of sudo is to grant users or groups of users access to elevated functions without having to reveal the Administrator's credentials. Therefore the password you'll want to use when prompted by the sudo command is in fact your user's password.

Additionally you can use the switch -l to sudo to see what specific permissions your user ID has been granted.

For example:

$ sudo -l
Password:
Matching Defaults entries for joeuser on unagi:
    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

User joeuser may run the following commands on unagi:
    (ALL) ALL

The above is stating that the user joeuser has all permissions, (ALL) ALL, on the system.

Idea #2 - Lacking sudo permissions

If you're finding that your password is correct, then it's likely that your account simply doesn't have an entry in Sudo's configuration files giving the user any permissions to use. To confirm this you can try running the command visudo to view Sudo's configuration file:

$ visudo
...
##
# Cmnd alias specification
##
# Cmnd_Alias    PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less

##
# User specification
##

# root and users in group wheel can run anything on any machine as any user
root        ALL = (ALL) ALL
%admin      ALL = (ALL) ALL

## Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d

NOTE: visudo is merely opening the file /etc/sudoers in vi in a protected manner so that no 2 users can stomp on it at the same time.

Idea #3 - Group membership

Typically with user's being granted access to sudo they'll be added to a special UNIX group called admin. You can confirm if your account is a member of this group like so:

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

This group is special since it's typically what shows up in the system's /etc/sudoers file granting users admin access via sudo via this line:

$ cat /etc/sudoers
...
...
%admin      ALL = (ALL) ALL
...
...

Idea #4 - TextExpander

I was able to find threads where other people were reporting that TextExpander was auto capitalizing the first word in a sentence, which was causing the first letter of their password to be capitalized when they would type it. You can disable TextExpander to see if this is the cause of your password issues with sudo.

Idea #5 - Corrupt account or password

There's a slight chance that your user's password may have become corrupt in some capacity which is rendering sudo unable to use it. To help eliminate this as a possible cause you can try resetting/changing your user's password. To do so access the Systems Preferences and then open up Users & Groups and select your user and click the Change Password button.

Additionally you may find some success with attempting to follow some of the steps in this guide titled: How-To Fix Corrupt User Accounts in macOS if you suspect your macOS user account has become corrupt.

NOTE: I'd save this last suggestion as something to try once you've completely eliminated everything else.

Idea #6 - Create another account

To eliminate any issues with the system itself, you may want to try creating another macOS user account and grant this user sudo access as well. Once you've created this account, attempt to use sudo -l and verify that it functions. If it does not, then your issue is likely with the system either being mis-configured or perhaps some files/libraries that are critical to sudo have become corrupt.

Idea #7 - An issue with certain commands

I noticed someone asking you in comments about how you were able to run the command sudo -l and provide your password, but in subsequent commands such as sudo ls it failed.

This got me to thinking that perhaps your issue has something to do with an alias, shell function, or shell script that's getting picked up when you run sudo ls.

To investigate this idea a bit more you can do the following:

$ set -x; sudo -l; sudo ls; set +x 

This will enable more verbose output from commands. The set -x is what enables this. The set +x at the end will disable this.

In between we'll run the sudo -l and the sudo ls commands so we can see what commands are actually getting run when these execute.

For example:

$ set -x; sudo -l; sudo ls; set +x
+ sudo -l
...
...
+ sudo ls
...
...
+ set +x

Your output should look the same, if you see something other than sudo ls then you may have an alias or shell function that's inhibiting your ability to run sudo ls.

You must log in to answer this question.

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