Solved

"root is not in sudoers list".  How do I get sudo to work?

Posted on 2011-03-23
22
847 Views
Last Modified: 2012-05-11
Not having much luck in the Mac area.  I can't do any sudo commands, because both my admin username and "root" are not on sudoers list!
Since I can't get into sudo using root, how can I get myself back on the list?
Very perplexing.
0
Comment
Question by:jampolis
  • 13
  • 8
22 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 200 total points
ID: 35200677
Hi,

using sudo makes no sense at all if you're logged in as root.
Just issue the required commands without prefixing them with "sudo" and they will work.

Use "visudo" as root to open your sudoers file and add your userid to it,
so you will be able to use "sudo" in the future when logged in with this ID.

Of course you could add

root           ALL = (ALL) ALL

to sudoers to be able to run sudo also as root in the future, but, as I said, this doesn't make sense.

wmp
0
 

Author Comment

by:jampolis
ID: 35200831
OK.  But I'm trying to comment out some lines that are screwing up a program.  To do that I need to get to private/etc/hosts.
Also, how do I navigate to the sudoers file to edit/add to it?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35200963
>> how do I navigate <<
Use "vidudo" as I wrote.
>> need to get to private/... <<
Where's the problem? root can do that without sudo, and once you added your userid to sudoers with appropriate privileges you can do that with sudo.

wmp
0
 

Author Comment

by:jampolis
ID: 35201062
Last login: Wed Mar 23 11:07:09 on ttys000
-sh-3.2$ visudo
visudo: /etc/sudoers: Permission denied
visudo: /etc/sudoers: Permission denied
-sh-3.2$ su root
Password:
sh-3.2# visudo
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
"/etc/sudoers.tmp" 0L, 0C

WHAT NOW?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35201299
You don't have a sudoers file yet, and visudo opened an empty one for you.

This is a bit strange, normally there is a sample file.

Anyway, "man sudoers" should have lots of examples.
Add

userid ALL = (ALL) ALL

for your own userid as a start.
0
 

Author Comment

by:jampolis
ID: 35201733
Last login: Wed Mar 23 12:08:30 on ttys000
-sh-3.2$ su root
Password:
sh-3.2# visudo -f /etc/sudoers




















iNPJ ALL = (ALL) ALL
root ALL = (ALL) ALL
:w! etc/sudoers

~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
-- INSERT --

Last login: Wed Mar 23 12:13:40 on ttys001
-sh-3.2$ su root
Password:
sh-3.2# sudo nano etc/hosts
root is not in the sudoers file.  This incident will be reported.
sh-3.2#

???????????? WHAT DID I DO WRONG?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35201800
Why did you use "-f /etc/sudoers"?
Why did you issue "w! /etc/sudoers"?

visudo manages the sudoers file on its own. Let it do its work.

What do you get with "cat /etc/sudoers"?

And why in the world do you insist in using sudo when logged in as root? It doesn't make sense, I keep telling you!

wmp
0
 

Author Comment

by:jampolis
ID: 35201943
OK OK As you can tell, I'm new at this. I'll try it as you say.
0
 

Author Comment

by:jampolis
ID: 35201957
I saw those commands in man visudo.  Sorry.  I don't know how to save the edit when it's done.
0
 

Author Comment

by:jampolis
ID: 35201975
Last login: Wed Mar 23 12:21:53 on ttys000
-sh-3.2$ su root
Password:
sh-3.2# visudo cat/etc/sudoers
usage: visudo [-c] [-q] [-s] [-V] [-f sudoers]
sh-3.2#
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35201976
:wq
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35201991
cat /etc/sudoers
NOT
visudo cat ...
0
 

Author Comment

by:jampolis
ID: 35202018
without the -F
0
 

Author Comment

by:jampolis
ID: 35202020
Without the -f

Last login: Wed Mar 23 12:56:47 on ttys000
-sh-3.2$ su root
Password:
sh-3.2# visudo /etc/sudoers
usage: visudo [-c] [-q] [-s] [-V] [-f sudoers]
sh-3.2# iNPJ ALL = (ALL) ALL
sh: syntax error near unexpected token `('
sh-3.2#
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35202028
ONLY visudo
WITHOUT ANY PARAMETER
0
 

Author Comment

by:jampolis
ID: 35202153
OK.  Here's as far as I've gotten.  The file (sudoers.tmp) is open on my desktop.
How do I finish, and how do I then edit  /private/etc/hosts ?


Last login: Wed Mar 23 13:12:41 on ttys000
-sh-3.2$ su root
Password:
sh-3.2# visudo /etc/sudoers
usage: visudo [-c] [-q] [-s] [-V] [-f sudoers]
sh-3.2# visudo -f sudoers


















iNPJ ALL = (ALL) ALL
root ALL = (ALL) ALL
:wq
:wq

~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
-- INSERT --
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35202205
Seems that you don't know how to work with vi.
Sorry, I've not been aware of this fact.

In your present situation it's best to hit the "escape" key and to type  :q!   afterwards. You will get back to your shell.
Now issue  visudo
Please post what you see.
0
 

Author Comment

by:jampolis
ID: 35203703
Last login: Wed Mar 23 13:14:29 on ttys000
-sh-3.2$ su root
Password:
sh-3.2# visudo /etc/sudoers
usage: visudo [-c] [-q] [-s] [-V] [-f sudoers]
visudo: sudoers.tmp unchanged
sh-3.2#
0
 
LVL 48

Accepted Solution

by:
Tintin earned 300 total points
ID: 35203723
Let's see if I can have a go at clearing things up :-)

Firstly, what woolmilkporc is saying is that there is no need to use sudo with root.

sudo is designed to give non-root users root privs for certain commands.

However, if you still want to persist in giving root sudo access, you need to type the following (exactly)

visudo
i
root ALL = (ALL) ALL <ENTER>
<ESC>
:wq! <ENTER>


Note that:

<ENTER> means press the Enter key
<ESC> means press the Esc key





0
 

Author Comment

by:jampolis
ID: 35203738
Last login: Wed Mar 23 17:48:45 on ttys000
-sh-3.2$ su root
Password:
sh-3.2# visudo





















~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
~                                                                              
"/etc/sudoers.tmp" 0L, 0C
0
 

Assisted Solution

by:jampolis
jampolis earned 0 total points
ID: 35203749
Tintin
OK.  I'm trying to edit the  /private/etc/hosts area but seemed to need sudo nano to do that.  Otherwise I get "permission denied".  I will try your formula and report back shortly.
Thanks
0
 

Author Closing Comment

by:jampolis
ID: 35230150
Woolmilkporc was very patient and kept trying in the face of my ignorance.
Tintin summed it all up neatly and it all works just fine!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now