Lost permission to use sudo commands
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.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
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
-
javex over 11 yearsHave 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)
-
Admin over 11 years@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.
-
javex over 11 yearsNo 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): wiki.archlinux.org/index.php/Change_Root#Change_root . Make sure to use the same architecture (its best to use the same iso)
-
-
terdon over 11 yearsThe OP's problem is that he has changed the permissions of his
/etc
folder. His sudoers file should be fine.