Removing execution bit recursively in /tmp
with chmod -R -x /tmp
does not prevent file execution from /tmp
.
First, it only applies to the files currently in /tmp
. New files created after you run chmod
will have no restrictions in them.
Second, if you remove the execution bit from another user's file it doesn't prevent the user from executing it. The user can add the execution bit back after you change it.
Third, the execution bit in directories is actually called "search" and has a different meaning than for files. Given this directory structure:
.:
total 8
drwxrwxr-x 2 root root 4096 ago 25 13:54 dir1
drwxrwxr-x 2 root root 4096 ago 25 13:54 dir2
./dir1:
total 0
-rw-rw-r-- 1 root root 0 ago 25 13:54 file1
-rw-rw-r-- 1 root root 0 ago 25 13:54 file2
./dir2:
total 0
-rw-rw-r-- 1 root root 0 ago 25 13:54 file1
-rw-rw-r-- 1 root root 0 ago 25 13:54 file2
If you remove "search" bit from dir1 with chmod -x dir1
you get this:
$ chmod -x dir1
$ ls -l dir1
ls: no se puede acceder a 'dir1/file2': Permiso denegado
ls: no se puede acceder a 'dir1/file1': Permiso denegado
total 0
-????????? ? ? ? ? ? file1
-????????? ? ? ? ? ? file2
$ cat dir1/file1
cat: dir1/file1: Permiso denegado
If you do this on /tmp you'll get an unusable temp dir, and several programs will crash on you.
So the noexec
mount option can't be replaced by chmodding.
If you really want to do it without adding a new partition1 or using a tmpfs/loop-mounted file (as suggested by Shane), the you can try the bind-fu in this SF answer
1: I'd also argue you wouldn't have this problem if you were using logical volumes ;)