Home » Infrastructure » Unix » Changing user while executing script
Changing user while executing script [message #195557] Fri, 29 September 2006 08:02 Go to next message
athyzafiris
Messages: 5
Registered: September 2006
Location: Switzerland
Junior Member
The problem is that i am executing a bourne shell script as one user which is fine but i have to copy a file that the user executing the script does not have access to therefore i have to change to another user. I want my script to relogin as the different user copy the file and logout coming back to the original user. I don't want the script to prompt the user for a password as i already know the password of both users and would hardcode the passwords in the script. Or if there is away to change users without considering the passwords at all that would be great.

If anyone can help me it would be much appreicated.
I don't want to do any system changes as this script will be run on different systems so i want the script to control everything.
Re: Changing user while executing script [message #195628 is a reply to message #195557] Fri, 29 September 2006 14:28 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
You could consider setting SUID bit on an executable(not script) you create to copy the file. The file owner is made to be the owner of the executable.

http://www.google.com/search?q=chmod+suid+sticky+4750
Re: Changing user while executing script [message #195762 is a reply to message #195628] Mon, 02 October 2006 04:10 Go to previous messageGo to next message
athyzafiris
Messages: 5
Registered: September 2006
Location: Switzerland
Junior Member
i have read through a number of documentation but how do i go about setting a SUID on the executable in the script.
Do i chmod 4000 the script as root before i execute it as a different user when i am logged in as that user? Or in the script do i chmod 4000 when executing the copy?

[Updated on: Mon, 02 October 2006 05:00]

Report message to a moderator

Re: Changing user while executing script [message #195823 is a reply to message #195762] Mon, 02 October 2006 11:53 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
you need to decide on the permissions you want to set. You add the "4" to the front of your regular parmissions. So if you would normally set the file to 755, you now set it to 4755 (from the program owner). It probably won't work on a script - only a program - becuase of security issues. It depends on your OS.
Re: Changing user while executing script [message #198992 is a reply to message #195557] Thu, 19 October 2006 09:20 Go to previous message
KCee
Messages: 16
Registered: October 2006
Junior Member
You could also try to think to use 'sudo'.
http://www.courtesan.com/sudo/

Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while logging the commands and arguments.

Previous Topic: Oracle IMP - canceling a import
Next Topic: calendar script
Goto Forum:
  


Current Time: Sat Dec 10 05:03:09 CST 2016

Total time taken to generate the page: 0.12820 seconds