Unable to use sudo

Asked by bhushi

Distro : Ubundo 10.10 using 8GB USB Persistence

I tried installing Elegant GNOME theme pack, for that I used following command
_______________________________________
sudo add-apt-repository ppa:elegant-gnome/ppa
_______________________________________

It ran for a lot of time, after that exited with error code 1

After restarting the system, I tried to continue with the next step which involved using sudo.

I got following message
_____________________________________
sudo: /etc/sudoers is not a regular file
sudo: no valid sudoers sources found, quitting
_____________________________________

browsed the /etc directory using Terminal. Somehow the sudoers file is now a directory and also the sudoers.d which is supposed to be a file.

I tried to visudo using recovery console but it won't allow me to create a new sudoers file.

Kindly let me know if any more details are needed.

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu sudo Edit question
Assignee:
No assignee Edit question
Solved by:
bhushi
Solved:
Last query:
Last reply:
Revision history for this message
Willem Hobers (whobers) said :
#1

Hi Bhushi,

can yo give some more information?

When does this problem occur?
Are trying to "sudo" in console?
Is there an error message?

Revision history for this message
bhushi (bhushandravid) said :
#2

Hi Willem, have updated the question..

Revision history for this message
Willem Hobers (whobers) said :
#3

Hi Bhushi,

I am sorry about my request for more info: I only saw the title of your question, and it seemed there was no more text. I now see you *did* provide more info.

Revision history for this message
Willem Hobers (whobers) said :
#4

I found some thread that seems to report the same sort of problem (in 8.10 though).

Have a look at the post added on November 3rd, 2008, 12:27 AM and further:

http://ubuntuforums.org/archive/index.php/t-968305.html

Does this help?

Revision history for this message
bhushi (bhushandravid) said :
#5

Willem, thanks for the prompt replies..

Unfortunately, the thread had no steps to fix the sudoers file.

The issue is that there is no /etc/sudoers file , instead there is a directory named sudoers.

Now to create a new sudoers file, I would need root access, which I can't have because sudoers file is missing.
It looks like a very common problem, however not too many solutions to this.

Do you think this is a bug with the installation procedure of Synaptic Package Manager ?

Last time while I was trying to install an application using WINE, it altered the /etc/mstab file in such a manner that I wasn't able to mount any drive.

Revision history for this message
Willem Hobers (whobers) said :
#6

Well, I can't say I am in my comfort zone with this problem (sorry), but have you considered using the live CD/memory stick? This should give you root access possibilities.

Revision history for this message
bhushi (bhushandravid) said :
#7

Ok, so if I try to use a Live CD...

1) Boot using Live CD
2) Mount the USB drive which has persistent USB 10.10
3) Since the USB would have casperRW file, how would I get access to the /etc/sudoers file ??

I am not aware of the intricacy of Casper file system...

Any help would be really appreciated..

Revision history for this message
karlrt (karlrt) said :
#8

you can reboot using the recovery-mode, which will give you root access

https://wiki.ubuntu.com/RecoveryMode

from there you can should be able to fix the sudoers file with visudo or you can enable the "normal" root by giving a password (# passwd root)

you can read it all at https://help.ubuntu.com/community/RootSudo

Revision history for this message
bhushi (bhushandravid) said :
#9

Hi Karlrt, can you help me how can I boot into recovery mode while I am running Ubuntu using USB Persistence ?

Revision history for this message
bhushi (bhushandravid) said :
#10

The login screen has an option to boot to <<Recovery Console>> , however it logs me in using the same account I log in to ubuntu desktop.

The normal user is not able to use sudo because the sudoers file is not anymore a file, somehow it is a directory..

I think this is a catch 22 situation, I won't be able to recover my Ubuntu now :(

This is very sad.. Ideally the file should be uneditable and there should be GUI around it so that no one can simply edit the file.. or may be only root can edit the file. Instead the file is open to modification and I think anyone can write a simple script to delete sudoers file..

Any views ? Any help would be much appreciated..

Revision history for this message
bhushi (bhushandravid) said :
#11

Yippieeeee finally found the solution to the omni-present sudoers issue.

To fix the sudoers problem

=> No need for recovery console
=> No need to boot using LiveCD
=> No need to even log out of your current user

The sudo command would fail in the following cases :
If the /etc/sudoers
a) is deleted during installation or it is converted to a directory
b) was edited in such a way that users don't have permission to do sudo
c) doesn't have permissions
d) can't be edited due to an I/O error (frequently encountered with USB Persistent installs)

The following solution is applicable to the first three issues. The last one can't be recovered and needs a new install.

Now the solution (No gurantees, try at your own risk. I was able to fix the problem using the following set of commands): -

a) if sudoers is deleted or converted to a directory
----------------------------------------------------------------
1) Login using your current user
2) Open terminal
3) Execute following command
     pkexec --user root rm -rf /etc/sudoers
     Will ask for password of the current user.
4) pkexec --user root visudo
    Will ask for password of the current user.
5) Paste the contents below this line (this is how the default sudoers file looks)

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL) ALL

# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

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

######################### END OF SUDOERS FILE #################################

6) Press Ctrl + o, it will ask name of the sudoers file, type sudoers there
7) Press Ctrl + x
8) pkexec --user root chmod 755 /etc/sudoers

Done ! Now retry the sudo command, you should be able to run it.

b) some users don't have permission
------------------------------------------------
1) sudo cp /etc/sudoers /etc/sudoers.bk
2) pkexec --user root visudo
3) Add the following line at the end of the file

 %user_name ALL=(ALL)ALL #here user_name should be replaced by the actual name of the user

4) Ctrl + O (save to /etc/sudoers)
5) Ctrl + X

c) doesn't have permissions (you would know this when it says permission denied while trying to use sudo)
-------------------------------------------------------------------------------
1) Login using your current user
2) Open terminal
3) pkexec --user root chmod 755 /etc/sudoers

Done ! Now re-try sudo command, you should be able to run it.

I hope this would be helpful to all people who have suffered due to sudoers issue.

Revision history for this message
karlrt (karlrt) said :
#12

great to hear from your solution. didnt know pkexec would work in such situations...

Recovery-mode is not in the login screen! its much earlier, before booting. If you use grub, there is an option "booting ubuntu in recovery-mode" if you dont see grub during startup its hidden, you just have to unhide it - just for the next time, you can read about this in grub2 manuals!