Solved

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

Posted on 2011-03-23
22
860 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

867 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

17 Experts available now in Live!

Get 1:1 Help Now