Whenever I create or copy few shell files to usb storage device, then I am not able to make them executable.
If I create test.sh, it’s default file permission will be 644, but when I execute
chmod 777 test.sh
no error reports and echo $? also returns “0”. But still ls -l shows permission as 644 and I can not execute it as ./test.sh
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Yes, this can occur if your device is formatted with a filesystem that does not support that kind of permission setting, such as VFAT. In those cases, the umask is made up on the fly from a setting in the fstab (or the hotplugging equivalent).
See, most probably, man mount for details. For example, for VFAT, we find:
Mount options for fat
uid=value and gid=value
Set the owner and group of all files. (Default: the uid and gid of the current process.)
umask=value
Set the umask (the bitmask of the permissions that are not present). The default is the umask of the current
process. The value is given in octal.
etc.
Method 2
It looks like your filesystem is mounted with the noexec option, which forbids executing programs on that filesystem by acting as if all execution bits in permissions were unset. If you use the user mount option (or if some user interface uses it under the hood), noexec is turned on unless you explicitly turn it off with exec.
Most USB sticks use the MSDOS-derived VFAT filesystem, which has no notion of permissions. You can only specify permission bits when you mount the filesystem, and these permissions apply to all the files on that filesystem.
If you don’t have permission to execute a script, call the interpreter explicitly:
sh /media/stick/test.sh
For a dynamically linked binary, invoke the dynamic linker.
/lib/ld-linux.so.2 /media/stick/myprog
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0