- Bash Script: How to read password without dispalying on the terminal

Below is the simple script which reads the user's password without displaying on the terminal.

Feel free to copy and use this code.

Source: cat passwd.sh
#!/bin/bash

# Here the input passwd string will get display on the terminal
echo -n "Enter your passwd: "
read passwd
echo
echo "Ok, your passwd is: $passwd"
echo

# Now, lets turn off the display of the input field.

stty -echo
echo -n "Again, please enter your passwd: "
read passwd
echo
echo "Ok, your passwd is: $passwd"
echo
stty echo

Output: ./passwd.sh
Enter your passwd: linuxpoison

Ok, your passwd is: linuxpoison

Again, please enter your passwd:
Ok, your passwd is: linuxpoison.blog@gmail.com

As you can see above in the scrip, with the use of stty we can enable or disable the screen echo.




source:http://linuxpoison.blogspot.com/2012/08/135781677516260.html