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.

link|improve this question

55% accept rate
feedback

4 Answers

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

link|improve this answer
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. – T. Brian Jones Jul 13 '11 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 ;) – Michael Lowman Jul 14 '11 at 18:38
feedback

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.

link|improve this answer
feedback

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

link|improve this answer
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 Jul 13 '11 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 Jul 13 '11 at 22:49
feedback
up vote 0 down vote accepted

After an exhaustive search, I failed to find any way to solve this and had to rebuild the server.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.