Crmgo Blog

Restoring file permissions after a failed chown, chmod

Restoring file permissions after a failed chown, chmod

On the donor system: Collect the correct "owner:group" permissions using the following command: ```bash find /etc /usr /bin /boot /dev /home /media /mnt /opt /proc /sys -exec stat --format 'chown %U:%G ${MPOINT}%n' {} \; > /tmp/restoreperms_chown.sh ``` Collect the correct file permissions using: ```bash find /etc /usr /bin /boot /dev /home /media /mnt /opt /proc…

Restoring file permissions after a failed chown, chmod

On the donor system:

Collect the correct "owner:group" ownership

find /etc /usr /bin /boot /dev /home /media /mnt /opt /proc /sys -exec stat --format 'chown %U:%G ${MPOINT}%n' {} \; > /tmp/restoreperms_chown.sh

Collect the correct permissions

find /etc /usr /bin /boot /dev /home /media /mnt /opt /proc /sys -exec stat --format "chmod %a ${MPOINT}%n" {} \; > /tmp/restoreperms_chmod.sh

Copy /tmp/restoreperms_chown.sh and /tmp/restoreperms_chmod.sh to the target system and execute them

Recheck on the target system where files still belong to user and group vasya, and create a script to change their ownership to root

find / -group vasya -user vasya -exec stat --format 'chown root:root ${MPOINT}%n' {} \; > /tmp/restoreperms_chown.sh

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.