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.


5 Answers 5


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.

# chown root.root /usr/bin/sudo
# chmod u+s /usr/bin/sudo

Otherwise when you figure out how to get root on the box you need to do those commands.

  • I had this problem too, but I was able to solve it by mounting my filesystem to a docker container (because docker runs as root) and calling those commands
    – RSmithlal
    Commented Apr 19, 2021 at 20:17

(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.

  • My data is on a separate EBS volume. The OS is on the small volume that is included with the EC2 instance (/dev/xvda1). I'm not sure if that drive can be mounted to a different instance. Commented Jul 13, 2011 at 21:34
  • It can't; the ephemeral disks are just that. The very first thing I'd do on install is sudo passwd, and add your user to wheel if needed. Always best to have a backup plan ;) Commented Jul 14, 2011 at 18:38

(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 only root can use chown(). 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 to chown their own files.

  • hmmm...if he can't be a superuser, I'm at a loss as to how the user asking the question could change the kernel to allow this.
    – mdpc
    Commented Jul 13, 2011 at 22:46
  • _POSIX_CHOWN_RESTRICTED is the only possible "trick", except that while the chown manpage suggests it could be altered, it can't. (or if you prefer: _POSIX_CHOWN_RESTRICTED means no tricks allowed, and Linux doesn't allow that to be changed.)
    – geekosaur
    Commented Jul 13, 2011 at 22:49

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:

chown root:root /usr/bin/sudo
chmod u+s /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.

You must log in to answer this question.

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