-   Linux - Newbie (
-   -   CentOS 5 "sudo" does not work as I want it to (

McFex 01-21-2011 06:46 PM

CentOS 5 "sudo" does not work as I want it to
Hi everyone!
I am new to Linux/CentOS and kind of learning by doing.

I searched the man pages and the How Tos and only found a partial solution to my problem:

I'm running a minimalized CentOS 5 on a VPS.

My problem:

I created a user. Let's call him user1.
User1 is member of the group wheel.
I changed the sudoers file, so that members of the group wheel can execute all the root commands without password.

%wheel  ALL=(ALL)      NOPASSWD: ALL
User1 is supposed to gain complete root rights with the su or sudo command now.
But this is what happens:

[user1@rs ~]$ sudo service sshd restart
sudo: service: command not found
[user1@rs ~]$

Also typing

[user1@rs ~]$ su
and entering the root password to have root rights

[root@rs user1]#
leads to the same result:

[root@rs user1]# service sshd restart
bash: service: command not found
[root@rs user1]#

I found out that by typing

sudo su -
user1 can become root and then executing the desired commands is no problem, but frankly that is not what I want.
I'd like to understand what I'm doing wrong and learn how to give user1 the right to execute root commands through sudo or su.

I used the search option with the term "sudo" and then "problems with sudo" and still had 1.000.000 results. I am also looking for the answer for hours now, so please forgive me if this question already exists and maybe link me to the right thread.
Thank you in advance,

snowpine 01-21-2011 07:00 PM

I'm not on my CentOS box right now, so I can't give you an exact answer (sorry) but I suspect the problem is the $PATH variable. If you type $PATH as user1 and compare it to the result of $PATH after becoming root suing su - you will probably see that /sbin is not part of user1's path.

You can verify whether this is the problem by typing sudo /sbin/service... instead of sudo service...

If my guess is correct then all you need to figure out is how to set $PATH for user1 to include /sbin. Sorry I don't have the answer at my fingertips but I am on a different computer at the moment. :)

McFex 01-21-2011 07:21 PM

You're my hero snowpine :D !
Thanks for the quick answer, that confirms what I just read going through another sudo guide.
I'll try to find out how to set $PATH for user1 to include /sbin, but will still be very greatful if you happen to get on your CentOS box, if you could post the solution here.

Thank you so much!

McFex 01-21-2011 07:42 PM


To add a directory to a single user's PATH, I need to change the .bash_profile in this user's home/user/ directory:

the lines that need to be in the .bash_profile to set an environment variable look like this:



export PATH

I figured it out :cool: !
This is the solution to my problem:


export PATH

Thank you snowpine for pushing me in the right direction :hattip:


snowpine 01-21-2011 07:52 PM

Yay! Glad it worked. :)

All times are GMT -5. The time now is 04:37 AM.