Search code examples
bashpasswords

How to make bash script ask for a password?


I want to secure the execution of a program with a password. How can I ask the user to enter a password without echoing it?


Solution

  • stty_orig=$(stty -g) # save original terminal setting.
    stty -echo           # turn-off echoing.
    IFS= read -r passwd  # read the password
    stty "$stty_orig"    # restore terminal setting.