3

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.

Bill Kary
  • 201
  • 3
  • 5

3 Answers3

5

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.

faker
  • 17,496
  • 2
  • 60
  • 70
  • 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 05 '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 05 '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 05 '11 at 21:34
1

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.

Rilindo
  • 5,078
  • 5
  • 28
  • 46
1

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

ewwhite
  • 197,159
  • 92
  • 443
  • 809