LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 05-15-2011, 11:32 AM   #1
thebombzen
Member
 
Registered: Dec 2010
Location: Noneya Business
Distribution: Linux Mint
Posts: 56

Rep: Reputation: 5
Question 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?
 
Old 05-15-2011, 11:33 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
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.
 
Old 05-15-2011, 11:39 AM   #3
thebombzen
Member
 
Registered: Dec 2010
Location: Noneya Business
Distribution: Linux Mint
Posts: 56

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by TobiSGD View Post
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)?
 
Old 05-15-2011, 11:44 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
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.
 
Old 05-15-2011, 11:50 AM   #5
thebombzen
Member
 
Registered: Dec 2010
Location: Noneya Business
Distribution: Linux Mint
Posts: 56

Original Poster
Rep: Reputation: 5
I did some googleing, and found to add the line

Defaults rootpw

before the other defaults. Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Running WinSCP with sudo su to non-root user MensaWater Linux - General 10 10-17-2012 04:27 PM
Gconf-editor settings not sticking for root, sudo user, or user when run sandaili Fedora 1 07-19-2008 09:31 AM
ambiguous redirect when running a script in /root/bin with sudo as normal user chadwick Linux - General 2 06-01-2007 10:57 AM
Running a script as root with sudo without entering the user password kloss Linux - General 8 10-10-2005 12:39 PM
SUDO as *non-root* user spratty Linux - Newbie 3 05-19-2004 04:35 AM


All times are GMT -5. The time now is 05:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration