Can I set Password to open my shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can I set Password to open my shell script?
# 1  
Old 06-23-2009
MySQL Can I set Password to open my shell script?

Hi All,

please help me on how to secure my shell script?

I chnanged it to read-only mode using 'chmod'.

but still i would like to set password for open the script.

Is there any way? Please help me!!

Thankyou all in advance!!

Smilie
# 2  
Old 06-24-2009
What exactly do you mean by "open the script"?

Reading the script, or executing it?
# 3  
Old 06-24-2009
see if crypt helps u.
# 4  
Old 06-24-2009
If you are asking for some way to password-protect a shell script when it runs, then it requires a little more coding in....

You didn't specify which language you're using...but if this is a BASH script, here's a link that provides a method to do this at runtime, checking the password against a second file:

Prompting users for passwords in a shell script? :: Free Tech Support :: Ask Dave Taylor!

Of course you can modify the arguments to fit whatever language you are running it under....
This would of course only work if you disable most access to the password file you make. I wouldn't suggest putting the password explicitly in the file since you've given read access to it... Smilie

For the sake of thoroughness, if you do decide to block read access to the file, here's an example using md5sum to check the password. Please note I'm half awake at the moment, so there's more than likely some way to make this look a little more elegant, but this runs when I test it on my machineSmilieSmilie

Once again using bash:

#!/bin/bash

echo -n "Enter password: "
read -e VALUE

TEST=`echo -n $VALUE|md5sum`

pwdchk="5f4dcc3b5aa765d61d8327deb882cf99 -"

if [ "$TEST" = "$pwdchk" ]; then
echo "the program will run"
else
echo "The program will not run"
fi

Last edited by DukeNuke2; 06-24-2009 at 02:10 PM..
# 5  
Old 06-24-2009
I see that you have changed your script to read only so I assume that you do not mind if other users see the internals of your script.

Are you trying to prevent other users from changing the contents of your script? Or are you saying that you would like users to have to input a password before they can run your script?

Please clarify.
# 6  
Old 06-24-2009
Quote:
Originally Posted by fpmurphy
I see that you have changed your script to read only so I assume that you do not mind if other users see the internals of your script.

Are you trying to prevent other users from changing the contents of your script? Or are you saying that you would like users to have to input a password before they can run your script?

Please clarify.
I think should be do not allow user to vi the file except the password is entered, but when excute the file no problem.
# 7  
Old 06-24-2009
MySQL

Thank you so much for all of your answers...

Well.. I would have make my requirement bit clear..

I have my script in a common folder.

I want to secure my script by viewing(as well as modifying) from other users.

Even though, I made it read only using 'chmod'. others may reset the mode using the same command..

So I would like to know from you all that is there any way to set a password and when ever 'vi filename' is prompted, it should ask a password to open..

Hope this may clear to you all..

if possible, kindly teach me is there any way to automate a script when ever the command 'vi filename' is prompted.

Thankyou all again!!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to set user password to never expire in UNIX servers

Hi, I have a requirement where in i need to write a shell script to set users password to never expire. I know the command which is used to perform the same .. which is chage command. But, could not figure out how to do the same in shell script. Could you please help me with the shell... (3 Replies)
Discussion started by: suren424
3 Replies

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. Shell Programming and Scripting

Script to set password in HP-UX 11.31

Hi, I am unable to set the password remotely. I am using the script as below: ep=`echo "$p" | /usr/lbin/makekey` ssh -t $i "/usr/local/bin/sudo useradd -c "$user_c" -m -d /home/$user_id -s /bin/ksh $user_id; /usr/local/bin/sudo /usr/sam/lbin/usermod.sam -F -p $ep $user_id" The... (0 Replies)
Discussion started by: Kits
0 Replies

4. Shell Programming and Scripting

Need a script to set non-expiry password

Hi All, I have a gateway server, from where I can connect any server via 'sudo ssh server_name'. Generally, if we need to run a command on any number of servers, we put server names in a file like '/tmp/ser_name' and execute it with for loop from gateway server. Now, I need to set non-expiry... (0 Replies)
Discussion started by: solaris_1977
0 Replies

5. Shell Programming and Scripting

Help to set permission on password files in script

Hi Techies I am stuck in a problem, I have written a script which is calling a second script which contains some command and password for quering on database. I do not want to disclose this command or specially password file. Please help.. Please have a look on directory structure and... (2 Replies)
Discussion started by: atul9806
2 Replies

6. Shell Programming and Scripting

script to set the password from *LK* to *NP*

okay here I go again... I have created a script which adds new user to /etc/password and which inturn creating a locked password in /etc/shadow but I am expecting to have *NP* for that particular user.Can someone help me with a script which can set the password for a particular user to NP in... (1 Reply)
Discussion started by: sintilash
1 Replies

7. Shell Programming and Scripting

how to set password/encrypt a shell script

Hi, I have written a shell script in unix for my customer. Now I want to make it only execute and not to read/write. Can anybody help me how to set password protect/encript my script. Thanks Suresh (3 Replies)
Discussion started by: suresh3566
3 Replies

8. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

9. Shell Programming and Scripting

set password using a shell script

Hi All How can I set password in linux.It is OK if it display password in plain text in script. manually i can set: #passwd Changing password for root Enter new password: Bad password: too weak. Re-enter new password: Password changed. # I want this to be done by script.Please let me... (2 Replies)
Discussion started by: tannu
2 Replies
Login or Register to Ask a Question