Lost permission to use sudo commands

3

1

I changed /etc folder permission to 711.

After doing that, I lost the permission to use sudo commands. Any way to change the folder permissions back?

What I have tried so far:

1) use su -, authentication failure

2) sudo ..., not working obviously.

sudo: unable to open /etc/sudoers: Permission denied

sudo: no valid sudoers sources found, quitting

sudo: unable to initialize policy plugin

Bencolder

Posted 2012-09-01T21:09:32.997

Reputation:

Have you considered booting a live cd, mounting your system and chrooting into it? If I recall correctly, you don't need a root password (but not 100% sure) – javex – 2012-09-01T21:12:15.023

@javex I'm running ubuntu in vmware, I know this might sound silly, but can you tell me how to do it? I only have iso files no physical disk. – None – 2012-09-01T21:15:16.367

No problem, just behave like you would have if you wanted to install it in a new VM: Mount your iso file and let it boot from disk (should be default). Then it gives you the same prompt as if you were about to install. Also check this entry (its ArchLinux, but its universal): https://wiki.archlinux.org/index.php/Change_Root#Change_root . Make sure to use the same architecture (its best to use the same iso)

– javex – 2012-09-01T21:17:47.423

Answers

2

There is a very good, detailed answer on using chroot here.

As user1461135 said, you need to add the iso to your Virtual Machine, boot using it and then mount your / partition. So, first of all check the name of your / partition. Log into your Linux System and run:

$ mount | grep "/ "

This should return a line like:

/dev/disk/by-uuid/d5cf13h31-f344-41237-92c5-e29c6006442h60 on / type ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)

or like this:

/dev/sda7 on / type ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)

In the first case, your partition is mounted by its UUID. To find out which device this UUID corresponds to run:

$ ls -l /dev/disk/by-uuid/

You will see that the UUID returned by mount corresponds to a specific /dev/sdX device. ON my system, it is /dev/sda7. If you have a line like the second example above, you already know the device.

Now, boot into the live session from the CD as suggested in the comments, create an empty directory, and mount your system there:

$ mkdir mountpoint
$ sudo mount /dev/sda7 mountpoint

Remember to replace sda7 with whatever your partition is. Once the system is mounted, I am not even sure you will need chroot. You can probably just run the chmod command directly:

$ sudo chmod 755 mountpoint/etc

Now, reboot your Linux system and things should be back to normal.

terdon

Posted 2012-09-01T21:09:32.997

Reputation: 45 216

0

Agree with the user above regarding using a live CD, this is probably your fastest route to success.

Mount the liveCD ISO file in VMWare before booting the image, then you can access the data on the hard drive.

Once you're there you'll want to check out the '/etc/sudoers' file - in there it'll tell you what groups are allowed to sudo. Mine looks like this:

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

This tells me both the 'sudo' group and the 'admin' group have full sudo access. Then you need to make sure your user is in the group that your sudoers file designates. I think mine is pretty standard for ubuntu installs.

Micah

Posted 2012-09-01T21:09:32.997

Reputation: 36

The OP's problem is that he has changed the permissions of his /etc folder. His sudoers file should be fine. – terdon – 2012-09-02T20:16:22.663