2

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?

2
  • 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, 2014 at 3:08
  • Alternativly run whoami and sudo whoami Feb 18, 2014 at 3:21

1 Answer 1

5

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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