Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I used ubuntu 12.04 (32bit).Today,I mistakes a command is executed:



sudo find / -type d -exec chmod -Rf a-wr {} \;

I can't login system;The System is only one user,disable the root.Who knows how to solve?

share|improve this question

closed as not a real question by Ulrich Dangel, Patrick, Chris Down, Renan, Shadur Apr 5 '13 at 17:27

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Describe your aims instead. Maybe we can help you then. –  Hauke Laging Apr 5 '13 at 13:06
This command will damage your system. Don't do it. What are you trying to achieve? –  Johan Apr 5 '13 at 13:09
I think "the system could not land" means "Now the system will no longer boot up". –  Johan Apr 5 '13 at 13:10
Thank you,Johan. The Command has been executed, I can not log in to the system. –  Long_Qi Apr 5 '13 at 14:14
Long time back I was amazed upon hearing that someone executed chmod -R a-x / as root. Seems that it's not that uncommon. Wondering if googling for this exact command would return anything. –  devnull Apr 5 '13 at 14:25

3 Answers 3

Taking read and write permission off of all directories in the system obviously destroys every normal distribution. This is nonsense.

Edit 1

The system can be repaired by booting another Linux (from CD/DVD/USB stick) and set the access rights correctly on all affected volumes. It may be complicated to restore the original state, getting it working again is easier. If there is just one user and no daemons providing services to the network there should neither be problems nor security risks.

mount -t auto /dev/whatever /mnt/targetvolume
find /mnt/targetvolume -type d -exec chmod 755 {} \;
find /mnt/targetvolume -type f -exec chmod 644 {} \;
chmod -R a+x /mnt/targetvolume/bin /mnt/targetvolume/sbin \
  /mnt/targetvolume/lib /mnt/targetvolume/lib64 /mnt/targetvolume/sbin \
  /mnt/targetvolume/usr/ /mnt/targetvolume/usr/bin \
  /mnt/targetvolume/usr/lib /mnt/targetvolume/usr/lib64 \

It is important to restore the correct permissions in /etc. My advice is to ask someone with the same distro (who at best should have installed all the software you have installed) to give you these:

# on a working system
getfacl --recursive /etc > acl-etc.txt
# on your system
setfacl --restore=acl-etc.txt /etc
# or from the rescue system
setfacl --restore=acl-etc.txt /mnt/targetvolume/etc

This can be further improved by

  1. checking whether all your files and directories within /etc exist in the reference system
  2. having the package manager check the access rights of the installed packages (e.g. rpm --verify package)
share|improve this answer
sudo find / -type d -exec chmod -Rf a-wr {} \;Wrongful execution of a command.the system is only one user,than I can't login.how to do/. –  Long_Qi Apr 5 '13 at 14:05
Command has been executed, I can not log in to the system –  Long_Qi Apr 5 '13 at 14:10
With -R, chmod affects more than just directories. It's stripped read and write permissions everywhere, for everyone. –  Michael Kjörling Apr 5 '13 at 14:55
@MichaelKjörling For everyone except root, of course. –  Hauke Laging Apr 5 '13 at 15:19
For root too; it's just that being euid 0 bypasses those security checks. –  Michael Kjörling Apr 5 '13 at 15:21

Let's see what has happened, and what (if anything) can be done about it.

sudo find / -type d -exec chmod -Rf a-wr {} \;

That breaks down to some fairly simple parts:

sudo find / -type d

Harmless in and of itself. This simply generates a list of all directories (that's what -type d is for) on the file system.


For each entry in the list, execute the given command

chmod -Rf a-wr {}

Now we are getting serious. {} expands to the current list entry, so the command executed for each directory is chmod -Rf a-wr $DIRNAME. To chmod, -R means recursive operation, -f suppresses error message output, and a-wr removes write and read permission from all users (a stands for all, which is distinct from e.g. o for non-owners).


End of command line to execute.

So (because passing the -R parameter to chmod giving it a directory causes it to perform the mode change on everything under it as well) the command you executed is effectively the same as the more readily understood

chmod --recursive --quiet a-wr /

I doubt I need to really say that pretty much anything on the system must be readable (and quite a lot of it writeable) by someone for things to work. Also note that removing read permission on a directory makes it impossible to get directory listings from it using ordinary means, which may wreak havoc elsewhere.

It may be possible to recover from this by reinstalling the packages that you have installed, but that won't help anything in e.g. your home directory, and there is no guarantee it'll work at all. You will need an appropriate architecture live CD (I'd recommend a live CD of the same OS you are using), boot using it, mount the root file system and drop to a shell. Then chroot /mnt /bin/bash where /mnt is the mount point for the system root file system, followed by mount -a to mount the remaining file systems.

Once there, dpkg -u --reinstall install '.+' should reinstall all packages, repairing most of the breakage. Note that it'll take a good while to complete.

Following this, go through your home directory and set reasonable permissions. You can start with something like the following, which should get you mostly up to speed at least.

find /home/me -not -type d -exec chmod 640 {} \;
find /home/me -type d -exec chmod 750 {} \;

This will set all directories to user read/write/execute, group read/execute, others no access, and non-directories to user read/write, group read, others no access, which is a reasonable baseline.

Again, there's no guarantee that everything will work following this repair (or that the repair will work at all; I haven't tried the exact command, and certainly not under the conditions you have created), but if it works, this should at least allow the system to boot. Once you have a bootable system, it does become much easier to perform further repairs.

A much easier alternative, if you have them, would be to practice your backup restoration practices.

share|improve this answer

Johan tried to alert you but you ignored. So now if you've done with the damage then boot the system in single mode and check the logs. Try to change permission of /tmp to drwxrwxrwt - 'chmod o+t /tmp' and check.

share|improve this answer
OP says they did this by mistake, and want to recover. @Johan's warning came way too late... –  vonbrand Apr 5 '13 at 14:55
Single boot the system to recover. –  Aasif Apr 5 '13 at 15:55
If it was that simple... –  vonbrand Apr 5 '13 at 15:57
Won't help - still needs to restore permissions and finding out which files should have been readable by all and which shouldn't will be a copper-plated bitch. He'd almost be better off backing up user data, reinstalling from scratch, and replacing the data with assumed-safe permissions. –  Shadur Apr 5 '13 at 17:26

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