Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Showing results for 
Search instead for 
Did you mean: 

execute as root?

Joseph Hoh
Frequent Advisor

execute as root?

How can I set a shell script to execute as root by another user. I don't want the user to be able to modify the script.
Rita C Workman
Honored Contributor

Re: execute as root?

Well, I generally have anything that needs root to run by root. That way I don't have to worry about the other user at all. If a job needs to be run by Oracle than as root I include the scripts into my cron jobs and set up a small file to do the su to Oracle and run the oracle job. I do the same for other users.

What I'm saying root I will run your jobs...but a user never runs root jobs. That way I know the jobs stay 'untouched'.

Just a thought,
Dan Hetzel
Honored Contributor

Re: execute as root?

Hi Jeff,

I agree with Rita, but I know it's sometimes unpractical.

An alternate solution would be to use 'SUDO' that you can freely download at the following address:

This utility allows you do define 'who' may run 'what' and under which usedid. It's quite powerful.

Best regards,

Everybody knows at least one thing worth sharing --
Honored Contributor

Re: execute as root?

setting to effective (not real) user id can be done with sticky bit.

The first line of the script must contain ie:

Change owner of the script

chown root <script>

Set sticky bit

chmod 5755 <script>

James R. Ferguson
Acclaimed Contributor

Re: execute as root?


You can do this by setting the set-uid bit. The script in question should be owned by root. Do 'chmod 45xx' on the script and when you run it from a non-root account, the effective uid will be that of root.

This is a VERY DANGEROUS practice. A better alternative is to use the 'sudo' utility or restricted SAM for functions you need to confer to trusted users.

Alexander M. Ermes
Honored Contributor

Re: execute as root?

Hi there.
Another hint. You should run this scripts under ksh, otherwise you could have weird results. I stepped into that trap last week
during an isnatll of 8.1.7
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"