LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-16-2009, 03:00 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
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?
 
Old 12-16-2009, 03:15 AM   #2
AleLinuxBSD
Member
 
Registered: May 2006
Location: Italy
Distribution: Ubuntu, ArchLinux, Debian, SL, OpenBSD
Posts: 272

Rep: Reputation: 37
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.
 
Old 12-16-2009, 03:17 AM   #3
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
ok. But how to do that?
 
Old 12-16-2009, 03:22 AM   #4
lcole
Member
 
Registered: Aug 2003
Location: Oregon
Distribution: Ubuntu
Posts: 50

Rep: Reputation: 18
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.
 
Old 12-16-2009, 07:21 AM   #5
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
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.
 
Old 12-16-2009, 10:27 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
You could also look at sudo http://linux.die.net/man/8/sudo
 
Old 12-17-2009, 12:38 AM   #7
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
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.
 
Old 12-17-2009, 05:55 AM   #8
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by ashok.g View Post
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.
 
Old 12-17-2009, 08:12 AM   #9
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
you can encrypt it using gpg -c <Script name>
 
Old 12-17-2009, 08:20 AM   #10
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by kdelover View Post
you can encrypt it using gpg -c <Script name>
But once it is decrypted, the user is free to examine it, copy it, etc.
 
Old 12-17-2009, 10:08 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,541
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Is it possible to use pam facilities?
 
  


Reply

Tags
password, script, set


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set mysql root password in script jakev383 Debian 1 08-14-2008 04:11 PM
Script to change password in initially set as *LK* RaelOM Programming 5 08-13-2008 03:25 PM
How to set password from script? ssy68 Linux - Newbie 2 02-20-2008 04:11 PM
HOW-TO? Create User, Set Password with script longtex Suse/Novell 13 10-02-2005 02:35 PM


All times are GMT -5. The time now is 08:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration