0

I hope you have a solution for that: I wanted to remove permissions to a specific folder with:

sudo chmod -rwx ./

But instead I had executed:

sudo chmod -rwx /

so I had removed all permissions to the root directory instead of the current folder.

Now I don't have access to any command, including sudo. I am on a rpi 4 running on Raspberry PI OS (Raspbian). I have a lot of important things, a pro website with a database. I have one or two backups of one database but not the others... I have a few importants programs without backups.

The OS does not boot actually.

Thank you if you can help me!

3
  • 4
    If you do things like this expect to break your OS. Restore from your backup. You COULD try mounting on a Linux OS and fix permissions.
    – Milliways
    Oct 29 at 10:10
  • 3
    @Milliways The damage is not that bad, he only removed permissions from a single folder. If it was chmod -R, then restoring from backup would make more sense. Oct 29 at 13:00
  • 4
    Hint: next time, use . instead of ./ - it's shorter to type and harder to make a problematic typo that way. Oct 29 at 13:03
3

This is an issue that cannot be corrected out of the running system. I would advise shutting down the Pi(1), removing the SD card and then attaching it via card-reader to a different computer running Linux (if you have one available). In the following steps, I will call that machine the "recovery machine".

(1) since you probably can't call shutdown anymore, you have to either try an ordered shutdown via the Magic SysRq keystroke Alt+SysRq+REISUB, or if that fails, you will need to perform a hard power-off instead

On your recovery machine:

  • Identify the device if necessary. To do so, you could e.g. execute
    ~ # journalctl -f
    
    as root user on your "recovery" machine and check for an entry like
    Okt 29 18:58:31 my-machine kernel: sd 33:0:0:0: [sdb] 62333948 512-byte logical blocks: (31.9 GB/29.7 GiB)
    Okt 29 18:58:31 my-machine kernel:  sdb: sdb1 sdb2
    
    that coincides with your plugging in the SD card. Assuming a standard Raspbian disk layout, the relevant device containing the root partition would be /dev/sdb2.
  • As root on the recovery machine, perform an fsck on the partitions of the SD card before mounting any of them:
    ~ # fsck -v /dev/sdb1
    (fsck output)
    ~ # fsck -v /dev/sdb2
    (fsck output)
    
  • Mount the root partition of the SD card. It should be the second partition:
    ~ # mount /dev/sdb2 /mnt
    
    If you execute an ls command in the root directory of your recovery machine, the entry for the /mnt mount-point will then look something like
    / # ls -l
    <...>
    d---------  18 root root  4096 Mar 14  2021 mnt
    
    reflecting the completely removed permissions on the / partition of your SD card.
  • Re-add the necessary permissions via
    / # chmod 755 /mnt
    
    If you run ls again, the entry should look more familiar, like
    drwxr-xr-x  18 root root  4096 Mar 14  2021 mnt
    
  • Afterwards, unmount, plug the card back in the Pi, and boot. It should work again (mainly because it seems that you didn't recursively revoke the rwx permissions).
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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