Command line utility to retrieve password, that has no echo back

Bash builtin read command doesn’t seem to support it, now I need to let user input a password while no echo should be displayed, what tool can I use?

Asked By: daisy

stty -echo
IFS= read -p 'Enter password: ' -r password
stty echo
printf 'nPassword entered: %sn' "$password"
  • stty -echo turns off the terminal echo, which is the display you’re talking about;
  • IFS= is necessary to preserve whitespace in the password;
  • read -r turns off backslash interpretation.

In bash you can also use read -s, but this feature isn’t standard across shells.

Answered By: Chris Down
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.