1

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

  • There is no simple undo for this. It would be faster for you to start over with a fresh install of Ubuntu – matigo Feb 23 '22 at 22:17
  • @matigo it looks like they didn't do it recursively - so maybe /usr/bin/sudo chmod ... would be sufficient to fix it? – steeldriver Feb 23 '22 at 22:22
  • @steeldriver so you mean try to run /usr/bin/sudo chmod ... in my terminal? – game lover Feb 23 '22 at 22:39
  • @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 – steeldriver Feb 23 '22 at 22:43

1 Answers1

3

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.

Tilman
  • 3,599
  • 21
  • 27
  • 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 – game lover Feb 23 '22 at 22:51
  • 1
    Yes, that might actually be faster. – Tilman Feb 23 '22 at 22:51
  • Thank you. But I am not sure I will not do same mistake again. Is it possible to somehow block chmod / ? – game lover Feb 23 '22 at 22:55
  • No. But you can make it habit to think twice before firing off a command starting with sudo. That's what we all do. – Tilman Feb 23 '22 at 22:59
  • @gamelover As Tilman said, always double-check a sudo command. I learned that the hard way. 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...) – cocomac Feb 23 '22 at 23:04
  • @cocomac and Tilman, Thank you for help! – game lover Feb 23 '22 at 23:18
  • 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. – vanadium Feb 24 '22 at 08:32