LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   sudo is not switching to root, running as same user instead (http://www.linuxquestions.org/questions/linux-software-2/sudo-is-not-switching-to-root-running-as-same-user-instead-880836/)

thebombzen 05-15-2011 10:32 AM

sudo is not switching to root, running as same user instead
 
Take a simple requires-root option, such as:

Code:

[Leo@chessman ~]$ cat /etc/shadow
cat: /etc/shadow: Permission denied
[Leo@chessman ~]$ su
Password:
[root@chessman Leo]# cat /etc/shadow
<contents here will not show you my passwords>
[root@chessman Leo]#

and it works as root.

But when I try to execute this command: sudo cat /etc/shadow, it doesn't work. This is what happens:

Code:

[Leo@chessman ~]$ sudo cat /etc/shadow
[sudo] password for Leo:
Leo is not in the sudoers file.  This incident will be reported.
[Leo@chessman ~]$

The only problem is, usually when I type sudo something, I expect that something to be run as root. For some reason, it isn't, it is trying to run it as Leo, but I was already logged in as Leo.

Can somebody help me fix this problem?

TobiSGD 05-15-2011 10:33 AM

It tries to run as root, but since Leo is not in the sudoers-file you are not allowed to use sudo to become root.

thebombzen 05-15-2011 10:39 AM

Quote:

Originally Posted by TobiSGD (Post 4356933)
It tries to run as root, but since Leo is not in the sudoers-file you are not allowed to use sudo to become root.

The only problem is, how do I add a line to the sudoers file so I can become root (with root password, of course)?

TobiSGD 05-15-2011 10:44 AM

To add a line to your sudoers-file you use the command visudo. It will open the file with the vi-editor, if you are not comfortable with that you can use your favorite editor with adding the EDITOR-variable.
For example, to use nano as editor you use
Code:

EDITOR=nano visudo
The sudoers-file is well documented, it should explain all what you need to know, but in short just add this line
Code:

Leo ALL=(ALL) ALL
Keep in mind that sudo uses the user's password, not the root password. If you want to use the root password you can either change that in the sudoers-file or just use su -c instead of sudo.

thebombzen 05-15-2011 10:50 AM

I did some googleing, and found to add the line

Defaults rootpw

before the other defaults. Thanks!


All times are GMT -5. The time now is 10:41 PM.