?
Solved

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

Posted on 2011-03-23
22
Medium Priority
?
923 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 8
22 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 800 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
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 

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
 
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 1200 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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