Link to home
Start Free TrialLog in
Avatar of jampolis
jampolisFlag for United States of America

asked on

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

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.
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jampolis

ASKER

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?
>> 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
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?
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.
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?
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
OK OK As you can tell, I'm new at this. I'll try it as you say.
I saw those commands in man visudo.  Sorry.  I don't know how to save the edit when it's done.
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#
cat /etc/sudoers
NOT
visudo cat ...
without the -F
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#
ONLY visudo
WITHOUT ANY PARAMETER
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 --
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.
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#
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!