Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Linux question regarding the sudo command and the root user. If I log into the root user using the su command, what is the difference between the following two commands?

root> sudo ./some_executable

and

root> ./some_executable

is there a difference? I am trying to use an executable and noticed that the executable works fine with the first command, but fails for the second command stating that I am not running the command as root. I always thought that the sudo/su commands allow you to execute commands with root privileges and so doing the first command would be redundant. However, I did noticed that the root user is in the sudoers file so I did not know if this is a bug in the executable or if there really is a difference between running a command logged in as root vs using sudo?

share|improve this question
    
The fact that you get an error that you are not running as root is very weird. Can you try running id and sudo id and see if there is any difference? –  spuder Feb 18 at 3:08
    
Alternativly run whoami and sudo whoami –  Eugen Rieck Feb 18 at 3:21

1 Answer 1

up vote 5 down vote accepted

Your environment variables will be different for the two instances.

sudo will be resetting some of your environment variables - read the man page for sudo and look at the -E option as well as the section on the sudoers config file.

Additionally your use of su and not su - to gain root means you do not have a true root environment when executing the file directly.

In summary, you have an environment mismatch between the two situations making one work when the other doesn't.

share|improve this answer
    
Thanks for clarifying! –  user972276 Feb 18 at 14:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.