2

I am trying to change the default sudo prompt that is used in macos to match what I am used to in linux. I want to know that I am expected to put my sudo password and not some other password.

I tried the ENV SUDO_PROMPT variable prompt first

❯ set SUDO_PROMPT '[sudo] %p : '

❯ echo $SUDO_PROMPT
[sudo] %p :

❯ sudo -v
Password:
sudo: a password is required

This is not working.

From the sudo documentation

passprompt_override
The password prompt specified by passprompt will normally only be used if the 
password prompt provided by systems such as PAM matches the string “Password:”. 
If passprompt_override is set, passprompt will always be used. This flag is off 
by default.

Yet when I tried to add this to sudoers file I keep getting an error. I guess I don't understand how the defaults override in sudo is supposed to work. There aren't vary good examples of setting boolean flags online that I could find.

sudo visudo /etc/sudoers
Password:
#
# Sample /etc/sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.

##
# Override built-in defaults
##
Defaults    env_reset
Defaults    env_keep += "BLOCKSIZE"
Defaults    env_keep += "COLORFGBG COLORTERM"
Defaults    env_keep += "__CF_USER_TEXT_ENCODING"
Defaults    env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
Defaults    env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
Defaults    env_keep += "LINES COLUMNS"
Defaults    env_keep += "LSCOLORS"
Defaults    env_keep += "SSH_AUTH_SOCK"
Defaults    env_keep += "TZ"
Defaults    env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
Defaults    env_keep += "EDITOR VISUAL"
Defaults    env_keep += "HOME MAIL"

Defaults    lecture_file = "/etc/sudo_lecture"

# Defaults  passprompt = '[sudo] password for %p: '

#Defautls   passprompt_override
1
  • 2
    Try export SUDO_PROMPT='[sudo] %p : '
    – lhf
    Commented Dec 9, 2022 at 11:12

2 Answers 2

4

If you use Bash or Zsh, variables must be set with

export SUDO_PROMPT='[sudo] %p: '

If you use Fish, use set -x to make the variable available to child processes

set -x SUDO_PROMPT '[sudo] %p: '
3
  • That is what I tried at the very being of the post. I am using the fish shell. So it looks like the problem is with fish.
    – nelaaro
    Commented Dec 12, 2022 at 15:34
  • 2
    @nelaaro Use of non-standard shells is worth mentioning in the question :-)
    – nohillside
    Commented Dec 12, 2022 at 15:54
  • 1
    @nelaaro Anyway, it's described in file:///opt/homebrew/Cellar/fish/3.5.1/share/doc/fish/cmds/set.html if you installed via Homebrew (and in the answer now as well).
    – nohillside
    Commented Dec 12, 2022 at 15:58
0

For me the difference in using fish [set][1] function

vim ~/.config/fish/config.fish
set -x SUDO_PROMPT '[sudo] %p : '

This is instead of just setting the variable, the -x to export is required. Doing it this way won't work.

set SUDO_PROMPT '[sudo] %p : '

You must log in to answer this question.

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