LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 03-23-2004, 09:38 AM   #1
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Mandriva 2008 Spring
Posts: 652

Rep: Reputation: 31
Shell script that changes user


I want to write a shell script that switches user runs another script and then exits the user account.
The only problem I am having is that the script askes for the password but I want the password to be in the script (the script will be execute only so the user will not be able to see the password).
 
Old 03-23-2004, 01:57 PM   #2
jcspray
Member
 
Registered: Mar 2004
Location: York, UK
Distribution: Ubuntu
Posts: 132

Rep: Reputation: 15
A script like this is probably not a very good idea. Perhaps you'd like to mention what it is you're trying to accomplish and a suggestion can be made.

If you're hell-bent on doing it like this, it's probably easiest to setuid the script to run as root, in which case "su username" will not prompt for a password.
 
Old 03-23-2004, 10:18 PM   #3
looseCannon
Member
 
Registered: Dec 2003
Location: Little Rock, AR
Distribution: Fedora Core 2, AIX, HP-UX, Solaris, Whitebox
Posts: 193

Rep: Reputation: 31
Re: Shell script that changes user

Quote:
Originally posted by davholla
I want to write a shell script that switches user runs another script and then exits the user account.
The only problem I am having is that the script askes for the password but I want the password to be in the script (the script will be execute only so the user will not be able to see the password).

Quickes, easiest, least messy, and least security compromising way to do this is with SUDO. it should already be installed on your system, if not it's pretty easy to add. Use the command 'visudo' to edit the configuration.

You'll need to add a command alias:
Cmnd_Alias SOMECOMMAND=/path/to/the/script

And you'll need to add a line for the user to run this script
userName ALL=(userToRunAs) NOPASSWD: SOMECOMMAND


Then in your script to execute the command as the other user just write the command as:
sudo -u userToRunAs /path/to/the/script

All done.
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 04:14 AM
Running script as user that does not have shell sschueller Linux - General 1 04-24-2004 04:06 PM
changing user in a shell script sanjith11 Programming 6 03-22-2004 02:18 PM
shell script user not ok slam Linux - General 4 07-24-2003 07:40 AM
Add User Shell Script DAC Programming 2 10-13-2002 04:12 PM


All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
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