Score:1

I accidentally did chmod wrong and some commands show permission denied

cl flag

I wanted to set chmod 644 to some files in my ubuntu like this

sudo chmod 644 ./*

but I accidentally did

sudo chmod 644 /*

It has corrupted my ubuntu, some commands start show permission denied. The image below is an evidence that I did wrong..

I am newbie in ubuntu and I absolutely don't know how to go back.. enter image description here

in flag
There is no simple undo for this. It would be faster for you to start over with a fresh install of Ubuntu
hr flag
@matigo it looks like they didn't do it *recursively* - so maybe `/usr/bin/sudo chmod ...` would be sufficient to fix it?
game lover avatar
cl flag
@steeldriver so you mean try to run /usr/bin/sudo chmod ... in my terminal?
hr flag
@gamelover the tricky part is deciding what to replace `...` with - unfortunately there's no blanket "undo" for this, you'd need to look at what the correct permissions of each directory (and file - if there are any in `/`) should be
Score:3
cn flag

The basic problem with this is that, by removing the execute permission bit from all top level directories, you have actually denied access to all files below those directories and consequently now you cannot execute any commands. (Except built-in commands of your shell, but those won't save you.)

The easiest way out I can imagine is:

  1. boot a live system from a CD or a USB thumbdrive
  2. mount your root filesystem at /mnt
  3. set the execute permission bits again with sudo chmod a+X /mnt/*

Note the capital X which will make sure that only directories will get the permission bit set.

Also note that on a standard Ubuntu installation there are two top-level directories (/lost+found and /root) which don't have execute permission for everybody. You can fix that later when your system is usable again.

game lover avatar
cl flag
ok then I guess reinstalling ubuntu will be the easiest if I have only small project there? I already have backup of my codes and personal files
Tilman avatar
cn flag
Yes, that might actually be faster.
game lover avatar
cl flag
Thank you. But I am not sure I will not do same mistake again. Is it possible to somehow block chmod / ?
Tilman avatar
cn flag
No. But you can make it habit to think twice before firing off a command starting with `sudo`. That's what we all do.
cocomac avatar
cn flag
@gamelover As Tilman said, always double-check a `sudo` command. I learned that [the hard way](https://askubuntu.com/questions/1383168/how-to-repair-ubuntu-after-messing-up-permissions-on-critical-directories). But, now you won't make that mistake again. The good news is that because you didn't delete anything, recovering any files that you need should be easy with a live USB (though also take this as a lesson to have regular backups...)
game lover avatar
cl flag
@cocomac and Tilman, Thank you for help!
vanadium avatar
cn flag
In this case indeed, the changes are limited to the directories in the root folder only, so this may indeed restore the system. On recursive changes, i.e. including all subdirectories, a reinstall would have been required.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.