Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My vendor send me a server with Centos5 installed. They have setup the machine to directly login with root account.

With the root account logined, i can run command like this:

service httpd restart

I dont like the root account able to login directly. So i added "PermitRootLogin no" in sshd_config file. Then i created another user and put it to the sudoer list.

The problem arise. When i login with this new user, i cannot run the "service command" anymore. It will prompt command not found. even though i "sudo su", i cannot run this command, can anybody tell me what to do? Thank you.

share|improve this question
up vote 5 down vote accepted

Your $PATH variable doesn't contain the required paths, and when using sudo su your $PATH is untouched.
However I would suggest not to use sudo su -, rather use:

sudo /sbin/service httpd restart

Only run the required command as root and not leave any root shells open.

share|improve this answer
good, i know the reason now. However, is it possible to alter the $PATH for a specific user, so that i don't have to type the full path instead? i found that for mysql, i can type solely sth like "mysql -u root -p", can we do the same for other command? – Bill Kary Jul 5 '11 at 15:32
Yes, edit this users shell settings (probably ~/.bash_profile) - add the desired paths to $PATH. On CentOS you are most likely missing /sbin /usr/sbin and /usr/local/sbin – faker Jul 5 '11 at 15:47
Depending on the configuration in the /etc/sudoers file you may find that the PATH overridden and need to update the path for the sudo command. – Rik Schneider Jul 5 '11 at 21:34

You are almost there. Next time, just do:

sudo su -

Running with "sudo su" means you use the environment settings of your regular user, not the privileged user, which mean that the service command was not in your path.

Either that or do:

/etc/init.d/httpd restart

If you want to bypass the service command completely.

share|improve this answer

You can use the full path to the command when you login. Try /sbin/service httpd restart.

share|improve this answer
You meant /sbin/service httpd restart or /etc/init.d/httpd restart – ghm1014 Jul 5 '11 at 13:47
Thanks. Typing from iPad. – ewwhite Jul 5 '11 at 13:48

Your Answer


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.