3

I am in a really bad condition right now.I am jotting down the steps I did to get myself into this situation.

My objective was to disable sudo on my machine.

I am running Amazon Ec2 Ubuntu 12.04

  1. I used this command to create a root password.

    sudo passwd
    

    At this moment I was 'ubuntu' user.

  2. I edited my /etc/sudoers file using nano and did the following.

    #ubuntu ALL=(ALL) NOPASSWD:ALL----This enabled no password
    ubuntu ALL=(ALL) ALL---this enables password
    

    So my file looked like (before I exited)

    #ubuntu ALL=(ALL) NOPASSWD:ALL
    #ubuntu ALL=(ALL) NOPASSWD:ALL----This enabled no password
    ubuntu ALL=(ALL) ALL---this enables password
    

Now when I use the sudo command I get the following error which is obvious as I messed up the file:

ubuntu@ip-10-144-143-249:~$ sudo
sudo: >>> /etc/sudoers.d/90-cloudimg-ubuntu: syntax error near line 4 <<<
sudo: parse error in /etc/sudoers.d/90-cloudimg-ubuntu near line 4
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

But when I use these commands su ,su root, it asks me for password which I setup in Step 1.

But every time I put the password in I get an authentication failure message despite being 100% sure I am giving the correct password:

ubuntu@ip-10-144-143-249:~$ su
Password:
su: Authentication failure

I don't know what to do know.I checked for few solutions over the web and one of the way suggested to detach and reattach the volume.This can be done but as this is a production environment a lot of problem would arise. Is there a way/hack which can be done so that I can get the sudo operations working??

3 Answers 3

1

Rahul, first of all you should repair the sudoers file.

create a sudoers file on desktop ans paste these lines into it:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

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

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

OK, now you have to replace your original sudoers file with the new file, use ctrl + F1 to switch to a tty, try to became root and type

mv /home/RAHUL/Desktop/sudoers /etc/sudoers 

IF you can't become root user, then you have to boot from live Ubuntu and then follow above steps.

2
  • Thanks Rahul but I use an amazon ec2 instance.How would it be possible for Booting from CD or in recovery mode command line?
    – ratr
    Jul 15, 2014 at 4:15
  • How you install ubuntu ?? o.O just make a usb boot drive from ubunut startup disk creator (From ubunutu) if you have windows you can use RUFUS tool to create startup disk and then boot from it.. Jul 15, 2014 at 11:30
1

Here is what I did To solve this Problem-

  1. Launched a same Hardware Like (the one that was messed up) instance.
  2. Stop the messed uo instance.
  3. ssh the complete ubuntu folder (Which had all the files needed).
  4. Started the replica Server and ensured that everything worked fine.(We use Mongo ,Mysql,Tomcat and Java).
  5. Once done I detached the elastic IP used for the messed up instance and attached to the replica instace.

Voila Now you have a new running instance with the same config and IP.

Time taken 30 mins.

0

You are putting the wrong password. sudo passwd is changing the password of the root user, not the password required to sudo. In addition, the root account is usually locked in ubuntu, so you cannot become root via su or su root, see here.

Whatever you did to 90-cloudimg-ubuntu is probably not related to the authentication failure. Are you sure that ubuntu ALL=(ALL) ALL---this enables password is syntactically correct? For a start, comments would begin with #.

To prevent any user from executing sudo, remove all users from the sudo group in /etc/group. Do you plan to log in as root afterwards?

5
  • Well I cant use sudo anymore as the sudoers file is corrupted.Also the root account was enabled .I set up the password using sudo passwd command which sets up the root password.Now I am unable to do 'su' as it says authentication failed and can't do sudo operations as sudo file is corrupt.
    – ratr
    Jul 15, 2014 at 3:23
  • If root account is enabled, log in as root and clean up your 90-cloudimg-ubuntu file again. What did you do to enable root?
    – noleti
    Jul 15, 2014 at 3:40
  • Thats what the problem is ,its not taking the root password.I setup up the password and edited the enable password in the sudoers file.Now the file is corrupt so I cant perform sudo operations and when I try to run as root its not accepting the password I set.
    – ratr
    Jul 15, 2014 at 3:46
  • @Rahul You are SOL, then, if it is not accepting the root password you set. You'll have to detach then.
    – muru
    Jul 15, 2014 at 3:49
  • Thanks muru.My bad. I think detach is the only option.Thanks guys for you help.
    – ratr
    Jul 15, 2014 at 4:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .