Shell Script accept password using read commnad

by on April 10, 2008 · 6 comments

  1. #!/bin/bash
  2. # Script accept password using read commnad
  3. # Not *very secure*, this script is for learning purpose only
  4. # -------------------------------------------------------------------------
  5. # This script is part of nixCraft shell script collection (NSSC)
  6. # Visit http://bash.cyberciti.biz/ for more information.
  7. # -------------------------------------------------------------------------
  8. PASS="abc123"
  9. read -s -p "Password: " mypassword
  10. echo ""
  11. [ "$mypassword" == "$PASS" ] && echo "Password accepted" || echo "Access denied"
  12.  


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • Amit Gupta

    Not working for me. Find the outpur below

    bash-3.00$ sh testing_pass.txt
    hi
    hi
    bash-3.00$

  • ivaylo

    #!/bin/bash
    PASS=”abc123″

    read -s -p “Password: ” mypassword
    echo Enter Password:

    if [ "$mypassword" = "$PASS" ]
    then echo “Password Accepted”
    else echo “Access Denied”
    fi

  • ngovuongbinhtay

    write a shell script with the following tasks:
    1. login (including your username and password).
    2.add, delete user name and password / add, delete group
    3. firewall.
    Note: as a general file.sh order from 1 to 3

  • ngovuongbinhtay

    help me …
    Write a shell script setup linux security policies include:
    1. password policy
    2. User policy
    3. firewall
    Note: Create a file.sh from 1 to 3. purposes:
    If (1) successful
    then 2
    If (2) successful
    then 3
    End

  • Prakash Rana

    Not working for me.

  • ashwini

    thank u friend

Previous Script:

Next Script: