Shell Script accept password using read commnad

#!/bin/bash
# Script accept password using read commnad
# Not *very secure*, this script is for learning purpose only 
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
PASS="abc123"
read -s -p "Password: " mypassword
echo ""
[ "$mypassword" == "$PASS" ] && echo "Password accepted" || echo "Access denied"
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • ashwini Nov 29, 2012 @ 9:51

    thank u friend

  • Prakash Rana Jan 23, 2012 @ 16:14

    Not working for me.

  • ivaylo Jan 22, 2011 @ 11:21

    #!/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 Apr 15, 2011 @ 0:46

      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

  • Amit Gupta Aug 16, 2010 @ 12:59

    Not working for me. Find the outpur below

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

    • ngovuongbinhtay Apr 14, 2011 @ 12:51

      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

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.