Solved

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

Posted on 2011-03-23
22
865 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

777 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