What to do when you remove permission for all users with chmod?

4

I am using Debian 8 stretch and I typed the command:

chmod  a-wx * 

Then my desktop turns black and I cannot reboot back to the OS.

scholar guy

Posted 2019-01-02T14:32:49.850

Reputation: 43

Were you running this command as a root user, or with sudo? What directory did you run it in? I'm guessing only your user's home? – Xen2050 – 2019-01-03T00:59:29.870

Yes I think I ran it in the folder containing home – scholar guy – 2019-01-03T05:18:51.377

That's a lot easier to fix then, I'll try an answer – Xen2050 – 2019-01-03T06:30:17.160

Welcome aboard. Although you got an answer here, I just wanted to make you (and others) aware of our sister site for questions about Unix & Linux

– Mawg says reinstate Monica – 2019-01-03T07:23:11.380

Answers

4

Since you only removed write & execute permission for files in your home directory, and it looks like there's no recursive option, so none of the contents of sub directories were affected, but you probably can't cd into the directories anymore which is probably causing problems.

You should be able to add those permissions back, and there's a few options to do that:

  • If you've got a live USB / DVD handy, just boot it then mount your main install's home partition with write access (rw).

  • Or, you can try booting your main install in Single-user mode:

    DEBIAN / UBUNTU root PASSWORD RECOVERY (with GRUB 2)

    1. First screen - grub - press e
    2. Modify kernel line: add single between ro quiet and at the end of this line add init=/bin/bash
    3. Press F10
    4. When the prompt is root@(none):/# you have to remount the / partition to have read-write access: mount / -rw -o remount

Now that you've got access to your user's home (it's a good time to backup any important files, just in case) cd to your user's home folder and just run a "reverse":

    chmod -v a+wx *

That should add back write permissions & let you cd into directories again, and hopefully boot OK.

It'll also add execute permission for regular files in your home directory, which isn't perfect but shouldn't cause any problems either. You could remove execute permission from non-hidden files with a GUI file manager, or something like

    find [home folder] -maxdepth 1 -type f  \! -name ".*" -print0 | xargs -0 chmod -v a-x

Another option is to just replace everything in your home with "defaults" from /etc/skel then the next boot should be like the very first boot.


Or yet another option would be to just create a new user (while booted in single-user mode) using adduser, and forget about or delete the whole old user (with deluser)

Xen2050

Posted 2019-01-02T14:32:49.850

Reputation: 12 097

1

Ctrl-alt and f1-f6 should work to get you into any other vtty.

From there your permissions can be restored by the root user.

Guy Gastineau

Posted 2019-01-02T14:32:49.850

Reputation: 301

0

I don't think it's possible, you may have to just salvage your files and re-install.

However, according to this post, you may try cutting all the files off your broken OS and pasting them back in. The permissions might not be copied and you might be able to boot back in. All of this would be done from a recovery OS of course.

And I would like to say my congratulations for bricking your system. That was quite a move.

TheChubbyPanda

Posted 2019-01-02T14:32:49.850

Reputation: 218

Well fortunately I have nothing important in the OS as it happened the first day I download Debian – scholar guy – 2019-01-03T05:20:04.230

In that case I would just reinstall to save you all the hassle. – TheChubbyPanda – 2019-01-03T08:58:35.880