Tuesday 14 October 2014

Protect a shell script with password

   How to protect a shell script with password 


Add following container before Your Shell Script or Any file which u want to Protect.

realpswd="Devendra"
read -s -p "Type Your Password: " pass
echo ""

[ "$pass" != "$realpswd" ] && echo "Wrong Password.. exiting..." && exit || echo "Continue"



 

--------------------------------------------------------------------------------------------------------------

For Ex. There is an example script.


root@devendra-desktop:~#vi deva.sh        #Paste Following Container to Your Shell Script#

realpswd="Devendra"
read -s -p "Type Your Password: " pass
echo ""

[ "$pass" != "$realpswd" ] && echo "Wrong Password.. exiting..." && exit || echo "Continue"
#!/bin/bash

echo -n "How many random numbers do you want to generate? "
read max

for (( start = 1; start <= $max; start++ ))
do
  echo -e $RANDOM
done



root@devendra-desktop:~#chmod a+x deva.sh
root@devendra-desktop:~#chmod ./deva.sh

root@devendra-desktop:~# ./deva.sh
Type Your Password:






####This protects your script from other users except root:

root@devendra-desktop:/opt# chmod 700 deva.sh


--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment