Is there a way to make part of a script run as a different (non-root) user? If it helps , the part to be run as a different user occurs at the end of the script
Edit :
OS -> Ubuntu 9.04
|
feedback
|
|
Use the sudo command in the script. In the form:
the sudo command runs command as the user username. If the script is being run as root, I don't think it will prompt for a password. Otherwise, this article discusses how to use sudo with password in one command line?, and this article discusses how to use sudo without password? | ||||
|
feedback
|
|
EricJLN's answer is good, but the serverfault advice is slightly dangerous - would allow anyone to run anything as root! So I'm posting here because I can't format the comment. I would recommend using visudo to give the permissions you need as precisely as you can. Type
If you do need to run this same thing on many hosts, you could open it up with:
But I would *not use either:
or username hostname = ALL The sudoer man page has lots of gory details | |||||||
feedback
|
|
not so sure about it, but if you want that ONLY the end of that script will run as a different user, you could add Am I missing something? Hope that helps, Regards | |||
|
feedback
|