conundrum! on a centos/redhat machine, how do you fix chmod if someone is trolling you and it now looks like this
$ chmod 644 /var/tmp/somefile /bin/chmod: cannot execute [Permission denied] $ ls -l /bin/chmod -rw-r--r-- 1 root root 38564 Nov 17 14:34 /bin/chmod
hmmmmmm…..
setfacl can modify permissions, so you could use it
$ /usr/bin/setfacl --set u::rwx,g::r-x,o::r-x /bin/chmod
you could copy another binary with the same permissions and overwrite its contents with chmod’s contents
$ ls -l /bin/ls -rwxr-xr-x 1 root root 87296 Nov 17 14:34 /bin/ls $ cp /bin/ls /tmp/chmod $ cat /bin/chmod > /tmp/chmod $ mv /tmp/chmod /bin/chmod
you can run ‘ld*.so.X’, the runtime linker, which will execute a dynamic executable such as 'chmod’, allowing you to use chmod to fix chmod
$ /lib/ld-linux.so.2 /bin/chmod +x /bin/chmod
you can use perl if it’s installed
$ /usr/bin/perl -e 'chmod 0755, qw(/bin/chmod)'
don’t panic, there’s always a way