1826123 Members
4714 Online
109690 Solutions
New Discussion

Re: sudo env

 
Phil Corchary
Advisor

sudo env

I have installed sudo on my 11.0 K570. The default is to execute commands as if I were root, which is what I want ... how do I get it to use root's environment?

philc
99% of the game is half mental. - Yogi Bera
7 REPLIES 7
Rick Garland
Honored Contributor

Re: sudo env

The users who are not listed in the sudoers files as "forbidden" to become root can just do the su -.

If they are in the sudoers file but the root access is not itemized, sudo su -

The entry in the sudoers file to prevent root access is
!/usr/bin/su *root*,!/usr/bin/su "",!/usr/bin/su su -

If the users do not have the above entry in the sudoers file, then sudo su - and this command will be logged (If loggin options are compiled in)
Phil Corchary
Advisor

Re: sudo env

I don't think I was clear in my request.

Certain commands to be executed via sudo as root require the root environment, esp. $PATH to either find the command, or for a script to execute correctly ... how to get this to work is the question.

e.g. commands in /usr/sbin ... not in normal path
99% of the game is half mental. - Yogi Bera
James R. Ferguson
Acclaimed Contributor

Re: sudo env

Phil:

Try re-sourcing your profile. As root, do:

# . .profile

...JRF...
Rick Garland
Honored Contributor

Re: sudo env

For various scripts to execute as root via the sudo command, I usually define the SUDO=/usr/local/bin/sudo (or where ever it is)environment variable then the scripts call the commands as so:
$[SUDO] .

As a script executes, each command that calls sudo is being logged.

Anthony Goonetilleke
Esteemed Contributor

Re: sudo env

Yup I know what you mean what I do is usually have an alias to sudo which is a small shell script, that passes $# to the script but sets the root PATH before executing it.
Minimum effort maximum output!
Rick Garland
Honored Contributor

Re: sudo env

To use root's environment, should be just the sudo su -

To get any users environment is the su - command, this should be no different.

Did you compile? If so, what options did you use?

A site that has good sudo info is www.courtesan.com
Phil Corchary
Advisor

Re: sudo env

Anthony - do you have a sample of that?
99% of the game is half mental. - Yogi Bera