• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Scipt file for a password.

Hi,

   Let's assume that there is a command that needs to be executed only by root. Is there a possibility that a script file can be used which will provide the password for the root. like :

su -c command
password : xxxxxxxx

this should happen without our entering the command.

is that possible? if yes how! and if no why?

-- Murthy.
0
snmurthy
Asked:
snmurthy
1 Solution
 
liormmmCommented:
Read sudo manual. You can restrict some user to run a certain command with root privileges. You can customize it to ask for a password or not.

If you have it installed, try visudo and you will be editing sudo configuration file.

Hope it helps.
0
 
cspangenCommented:
Yes, you can use a expect script file to supply the password to a root command. I have an example of the script below.

#!/usr/bin/expect --
stty -echo
log_user 0
spawn su
expect "Password:"
send "$password\r\n"
log_user 1
expect ">"
send "$command\r\n"
expect ">"

The $password variable needs to be substituted with the correct password, and the $command variable needs to be substituted with correct command to execute.

You can also use this other script to do the same thing.

#!/usr/bin/expect --
stty -echo
log_user 0
spawn su
expect "Password:"
send "$password\r\n"
log_user 1
expect ">"
send "$command\r\n"
expect ">"

There is security risks involved in puting a root password in a file. If a person can read the file then they can obtain the root password of the operating system.There are are solutions to that problem. If you need a secure solution let me know.

Carl
0
 
-CrashOverride-Commented:
in root there is no password at first u login as root and ther is no passwor and if u wana make a password then you type in :
passw
and type in ur password
0
 
CleanupPingCommented:
snmurthy:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
TheWeakestLinkCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept comments from cspangen as answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheWeakestLink
EE Cleanup Volunteer
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now