LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can I set the password for a script??!! (https://www.linuxquestions.org/questions/programming-9/can-i-set-the-password-for-a-script-776015/)

ashok.g 12-16-2009 03:00 AM

Can I set the password for a script??!!
 
Can I set the password for a script such that if I want to run that script I need to provide the correct password. Is it possible in bash scripting?

AleLinuxBSD 12-16-2009 03:15 AM

It's possible using the attribute available on the OS.
For example root script require you specify the password for have the privileges to run it.

ashok.g 12-16-2009 03:17 AM

ok. But how to do that?

lcole 12-16-2009 03:22 AM

Yes there are various ways both secure (encrypted) or easily discovered if not encrypted.
Here is a link that might help http://wiki.tcl.tk/3594
Try some google searches for more introductry information.

pcunix 12-16-2009 07:21 AM

Simple way:

Create a user "runit"

The script you want to protect is /usr/bin/yourscript


Code:

# chown runit /usr/bin/yourscript
# chmod 700 /usr/bin/yourscript

Create the script "/usr/bin/doit" to contain

Code:

su - runit /usr/bin/yourscript
Make "doit" executable

Code:

# chmod 755 /usr/bin/doit
When an ordinary user runs "doit", they'll be asked for "runit"'s password. If they enter it correctly. "yourscript" will run.

chrism01 12-16-2009 10:27 PM

You could also look at sudo http://linux.die.net/man/8/sudo

ashok.g 12-17-2009 12:38 AM

pcunix,

Whatever you said I close to my requirement. But, I want to use a password for a specific script which means that I can run that script by providing that password rather than some other user's password.

pcunix 12-17-2009 05:55 AM

Quote:

Originally Posted by ashok.g (Post 3794843)
pcunix,

Whatever you said I close to my requirement. But, I want to use a password for a specific script which means that I can run that script by providing that password rather than some other user's password.

So you create a "user" whose only purpose is to provide the context to run that script.

kdelover 12-17-2009 08:12 AM

you can encrypt it using gpg -c <Script name>

pcunix 12-17-2009 08:20 AM

Quote:

Originally Posted by kdelover (Post 3795374)
you can encrypt it using gpg -c <Script name>

But once it is decrypted, the user is free to examine it, copy it, etc.

catkin 12-17-2009 10:08 AM

Is it possible to use pam facilities? :twocents:


All times are GMT -5. The time now is 10:11 AM.