How to make script password protected

Hi All,

     I want to make my script password protected.

     i e: if somebody runs my script it should prompt for password.

     Can somebody help me in to execute the same??

Thanks in Advance :b:

hi,
I got a very simple idea.

Write something like this in the beginning of your script for the password checking.

...
ACTUAL="perftest"
read -s -p "Password: " enteredpass
echo ""

[ "$enteredpass" != "$ACTUAL" ] && echo "Sorry" && echo "exiting" || echo "Conti.."
...

Since you will be storing your password in your script itself, you have to protect your shell script by using shc.
Generic shell script compiler(shc) creates a stripped binary executable version of the script specified with -f on the command line. (shc encrypts shell scripts using RC4)

Hope this helps.

//Jadu

I am not very clear about shc,

Can you tell me how to make a sciprt as shc??

Well,
I have a post here,

Jadu's Workshop: How to protect a shell script

which will help you.

Hi,

I tried encryting a bash script, and I received the below error...

-bash: shc: command not found

Is there a different command to execute bash scripts??

reasonably simple password encrypter process:

you could use perl to crypt a password e.g.:

perl -e "print crypt('password','AA');'\n'"

then use perl in your script to check the password e.g.:

/usr/bin/perl -e "print 'match' if crypt('password','AA') eq 'AA6tQYSfGxd/A';"

and do the test / exit or continue with script piece

but as noted already this does not hide the contents of the script - for very basic security it'll do though...

achararun you have to get shc install in your box if ! present, get it from here, Francisco Rosales, home page
and follow my blog link.

I installed SHC and was successfully able to encrypt the scripts and I executed the script as well, but I noticed sometimes the scirpts gets in to hung status and even ctrl+c,d,z doest not work. I have to forcibly logout of the session.

Can you tell me why its happening??

An alternative approach would be to use Sudo to execute your script (Sudo can su to accounts other than root)...

this problem should be tackled at a higher level.
will your script be run by anybody or only for authorized personal ? and what does your script do, if you don't mind.

Hi ,

 My scripts triggers an Batch application, which is very critical. So I dont want my script to be executed by other.

then set your environment for proper access. Only authorized personal will be running the script and nobody else.