Android - Run downloaded shell command without root?
Yes, this is by design. You can't execute binaries from the SD card without system or superuser privileges (and remounting it without the noexec
option) because otherwise apps could just download and execute malicious code at will. In older versions of Android the SD card also did not have emulated permissions so chmod
would naturally fail.
Some devices/older versions of Android might allow execution from /data/local/tmp/
, so you could try putting it there. Otherwise, you'll probably need root.
Android, just as Linux, prevents any user but root, to change the permission bits of any file not owned by such user. That said, chmod is ineffective, unless you have root privileges.
By the way, even if you had such privileges, you wouldn't have been able to change permissions, as long as the target path is /storage/sdcard0 or /storage/emulated/0. This depends upon a security policy, which is implemented in the form of the FUSE filesystem, and can be circumvented by moving to /data/media/0 or /data/media/emulated/0, and chmoding the file from this position. Please notice that this procedure will let you execute a script only if you launch it from one of the abovementioned locations.
Lastly, it should be noted that the Android port of chmod does not support symbolic editing of the flags (+rwx
and so on), so you'll be forced to edit them via their corresponding octal values. You'll also do need root privileges, in order to be able to access /data/media. Trying to cd
to such directory by using user privileges results in a Permission denied error.