What did I do to sudo? /etc/hosts is NOT the issue

Asked by Michael James

I have reverted my /etc/hosts back to a normal state that I know SHOULD work and sudo keeps giving me this error:
sudo: unable to resolve host michaeljame

This is HIGHLY irritating. Why does sudo need to check the host file anyways?

Any other random files sudo checks before working?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Michael James
Solved:
Last query:
Last reply:
Revision history for this message
Sean Sosik-Hamor (sciri) said :
#1

sudo checks hostname because it's possible to restrict sudo access on a per-machine basis. Example from the sudoers manpage:

        ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

       would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm as root on the machine
       rushmore as root without authenticating himself.

Please check your /etc/sudoers file for instances of michaeljame. The sudoers configuration to allow a group to execute any command without authenticating is:

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

So, if michaeljame is indeed in sudoers, replace it with ALL. You may need to reboot into single user or recovery mode to run visudo if you're unable to sudo visudo to see the sudoers file.

Revision history for this message
Sean Sosik-Hamor (sciri) said :
#2

One more thought that occurred to me about 5 seconds after hitting Add Answer. Is (was?) your hostname michaeljame or is your username michaeljame? It could be possible that your username was put into the hostname field in sudoers or vice versa.

Revision history for this message
Michael James (mbj1103) said :
#3

My username is michael, and sudo worked before; in fact it is working now. Somehow I think it has to do with the wireless network I am on. I looked through my /etc/hosts plenty (thankfully I had enabled root stuff) with su and found nothing wrong. I even checked my sudoers file and it is a normal healthy file. I am not going to mark this as answered until I get home and get on my home network and sudo works.

Back to why. Why would sudo be per-machine? I can' t think of a time when that would be useful.

Random question: what will happen if I edit sudoers with say nano?

Revision history for this message
subliminalfix (na1tr2lp-deactivatedaccount) said :
#4

try this site www.slashdot.org

Revision history for this message
Michael James (mbj1103) said :
#5

It worked fine at home; but then after a terminal crashed and sent me back to GDM (logged in fine) then sudo stopped working! I shall reboot! This did nothing. Grrr. Any ideas as to what could make sudo so volatile? I recently installed likewise-open and connect to an active directory, then disconnected because sudo and samba where giving me problems. I will purge likewise and see what comes of it! It worked. So it looks like likewise-open and likewise-open-gui messed with sudo's files in some way.

The next question: Should I report a bug report (in likewise) about this with a link to this question?

Revision history for this message
Michael James (mbj1103) said :
#6

Okay, it stopped working after I suspended and woke up. I dont know what is causing this and this is REALLY sporatic.

Revision history for this message
subliminalfix (na1tr2lp-deactivatedaccount) said :
#7

sudo -help

or

Usage: su [options] [LOGIN]

Options:
  -c, --command COMMAND pass COMMAND to the invoked shell
  -h, --help display this help message and exit
  -, -l, --login make the shell a login shell
  -m, -p,
  --preserve-environment do not reset environment variables, and keep
                                the same shell
  -s, --shell SHELL use SHELL instead of the default in passwd

im sorry i dont have a direct answer and the troubling thought is how would your network connection interfere with your man capability

peace =]

Revision history for this message
Michael James (mbj1103) said :
#8

Hm, that would work but the problem is that Ubuntu is heavily dependent on sudo.
Is it possible to upload a file in the questions section of launchpad?

Revision history for this message
Michael James (mbj1103) said :
#9

I could upload my hosts file and sudoers.

Revision history for this message
Michael James (mbj1103) said :
#10

This is my hosts file:
127.0.0.1 localhost MICHALEJAME.kcd
127.0.1.1 michaeljame
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Now sudoers (the uncommented parts):
Defaults env_reset
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL

Revision history for this message
Sean Sosik-Hamor (sciri) said :
#11

> Back to why. Why would sudo be per-machine? I can' t think of a time when that would be useful.

Because large network installations will use the same sudoers file on every machine on the network. Edit the file in one place, then rdist or rsync it out to dozens, hundreds, or thousands of machines in a Datacentre. By allowing per-machine access control in sudoers they can maintain privileges for every machine in a Datacentre in a single file.

Revision history for this message
Michael James (mbj1103) said :
#12

Okay, very nice answer, that answers why sudo does what it does, Thanks!

Now, what are the files that sudo needs that I could reset? I REALLY don't want to re-install and deal with moving my home directory over. I tried re-installing sudo to no avail.

Revision history for this message
Gábor Náray (xlii) said :
#13

I had begin to look after your program.

The first thing I checked was 'man sudo'. I haven't found the answer yet, but there some very promising detailed explanations about /var/adm/sudo and var/run/sudo, Try it.

Revision history for this message
Gábor Náray (xlii) said :
#14

A workaround can be to put in live cd, chroot to your system - that way you will gain root privileges - and enable root account.
Reboot in your system and you will have root rights to solve whatever problem is with sudo.

Revision history for this message
Sean Sosik-Hamor (sciri) said :
#15

> Random question: what will happen if I edit sudoers with say nano?

You can, but nano doesn't sanity check before writing the file. visudo syntax checks before allowing a write. If you don't like vi, you can "export EDITOR=nano" and visudo will wrap itself around nano. There's also a system-wide command to set the default editor but I forget it off the top of my head.

       visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers
       file against multiple simultaneous edits, provides basic sanity checks, and checks for parse
       errors. If the sudoers file is currently being edited you will receive a message to try again
       later.

But back to your actual problem; I can't think of anything else off the top of my head. Sorry. But at least I gave you some insight into sudo voodoo. ;)

Revision history for this message
Gábor Náray (xlii) said :
#16

Well I see, you had all this. Okay, looking further.

Revision history for this message
Gábor Náray (xlii) said :
#17

Silly question but you changed /etc/hosts. Have you canges /etc/hostname too to be consistent? Or the problem no longer exists?

Revision history for this message
Michael James (mbj1103) said :
#18

My hostname file matches with "michaeljame" as the only text in it.

Oh, wow. This is the output of a terminal that I did after rebooting. Each command is within 3 seconds of each other:

michael@michaeljame:~$ sudo
usage: sudo -h | -K | -k | -L | -l | -V | -v
usage: sudo [-bEHPS] [-p prompt] [-u username|#uid] [VAR=value]
            {-i | -s | <command>}
usage: sudo -e [-S] [-p prompt] [-u username|#uid] file ...
michael@michaeljame:~$ sudo nano /etc/hosts
sudo: unable to resolve host michaeljame
michael@michaeljame:~$ sudo
sudo: unable to resolve host michaeljame
michael@michaeljame:~$ su
Password:
root@michaeljame:/home/michael# nano /etc/hosts

Thankfully I have su and a root password set.

Revision history for this message
subliminalfix (na1tr2lp-deactivatedaccount) said :
#19

perhaps try this command in your terminal

sudo dpkg --configure -a

you can aggressivly try to overwrite the sudo if that does not work with

sudo apt-get install -f

but before you do that or the other

if you have made upgrades to your system

sometimes ghost files or conflicting data gets left inadvertantly behind

run this just to make sure

sudo aptitude autoclean

hope that helps

peace =]

Revision history for this message
Michael James (mbj1103) said :
#20

This is quite possibly the most interesting bit I have discovered with this. Sudo works fine in the ttys after booting and before loging in through gdm/X. Sudo keeps working even after I log in with GDM UNTIL I hit my desktop. Then sudo stops working by first the command sudo takes a while to give an output then it gives me the unable to resolve hostname thing. So there is something in my login process that does it. I will log in as root and see how that goes. (how silly to be using sudo as root!)

Revision history for this message
Michael James (mbj1103) said :
#21

Ok, sudo does not work under root either (only after login with x/gdm). Sudo is then corrupted until the computer is restarted. Re-installing sudo or gdm doesn't fix this.

Revision history for this message
Michael James (mbj1103) said :
#22

I ran clamtk and found that I have 4 viri. I am just going to re-install. Two of the viri were in GDM one was in a file called "cache" in /var/. The last one I could not find out where it was. I have no idea what got me those viri. The last thing I remember that I did before sudo stopped working was disconnect from an active directory using likewise-open. If someone has time, look over the likewise code, perhaps it opened a backdoor or something.