I accidentally changed ownership of /usr/bin/sudo
to my current user (i also did this for some other stuff in my /usr
directory). I can't change any of them back because I need ownership of /usr/bin/sudo
to be root to do so. I do not have root access because I'm on an Amazon EC2 instance running linux.
Here's what I did (foolishly I know):
sudo chown -R ec2-user.ec2-user /usr/
I've also hosed a ton of other stuff in the process, but I think it can all be solved if I can reset ownership of /usr/bin/sudo
Please help. I'm brand new to Linux admin and am doing everything from the command line.
I have my important data on a separate, mounted EBS, but I'm awful with server admin and it'll probably take me an entire day to setup a new instance, but am afraid that is my only option.
If you have any scripts that run via cron as root and you still have the ability to edit them you could add the following.
Otherwise when you figure out how to get root on the box you need to do those commands.
(repeating my SE answer)
Are you running on an EBS volume? Can you afford to shutdown the instance for a few minutes?
If you do, then you can temporarily stop the current instance, start another instance, mount the EBS volume of the first instance and fix its permissions, then unmount it and re-start the first instance.
(rephrasing this since apparently it wasn't understood by some people)
Linux kernels advertise
_POSIX_CHOWN_RESTRICTED
as true, which is defined to mean that onlyroot
can usechown()
. If it were set false, this would mean that there is a way for ordinary users to change the ownership of their files.chown(3)
has wording which suggests that it is possible to change_POSIX_CHOWN_RESTRICTED
at the kernel level; Linux doesn't actually allow it to be changed, though, so there is simply no way for non-root
tochown
their own files.After an exhaustive search, I failed to find any way to solve this and had to rebuild the server.
Reboot your computer and hold F8 after the BIOS splash to bring up the GRUB boot menu. If you use one of the popular distros of linux (something like Ubuntu), there should be an option to start linux in recovery mode (the option might be found under an 'Advanced Options' sub-menu if you use GRUB 2). Start linux in recovery mode, and (if you use a popular distro) you should eventually be presented with a short menu of recovery options. First, select the fsck recovery option to remount / in read-write mode and mount all the other file systems in fstab. Then select the option that will give you a root prompt. Since the shell is logged in as root, all commands will be run as root without needing the sudo command. You can use this to repair the permissions on /usr/bin/sudo:
After you've done this, you can select the 'resume normal boot' option (or just restart your computer if you don't have one) and log in normally and use the sudo command to repair the rest of your permissions. To do that, you usually have to copy permissions from another computer that has permissions that are 'close enough'. I ran into this problem with my desktop when I manually installed a cross-compiler I had just created using rsync with the -a flag. After I realized that I wanted the cross-compiler's files to be chown'ed to root and not me, I foolishly ran chown -R root:root /usr and nuked my permissions by accident. Fortunately, I had a laptop of the same distro and it had almost the same set of installed packages. I copied the permissions from it and solved my permission problems in under an hour.