4

I'm on Android using Termux and copied a file from my sdcard to my Termux home folder. (I use a file explorer app with root permissions for that..) Now having the file in my home dir I checked what my user name and groups are and set me as the owner of that file and also set permissions to 777.

$ whoami
u0_a87
$ groups
u0_a87
$ su -c chown u0_a87:u0_a87 Files.zip
$ su -c chmod 777 Files.zip
$ ls -la
total 7292
drwx------ 2 u0_a87 u0_a87    4096 Jul 22 09:13 .
drwx------ 4 u0_a87 u0_a87    4096 Jul 22 09:13 ..
-rwxrwxrwx 1 u0_a87 u0_a87 7454766 Jul 22 01:24 Files.zip$ unzip
Files.zip
unzip: can't open Files.zip[.zip]
$ cat Files.zip
cat: Files.zip: Permission denied

Why is it that I can still not access it?

This worked just fine btw:

$ mkdir test
$ zip -r test.zip test
  adding: test/ (stored 0%)
$ ls -la
total 7300
drwx------ 3 u0_a87 u0_a87    4096 Jul 22 09:31 .
drwx------ 4 u0_a87 u0_a87    4096 Jul 22 09:13 ..
-rwxrwxrwx 1 u0_a87 u0_a87 7454766 Jul 22 01:24 Files.zip
drwx------ 2 u0_a87 u0_a87    4096 Jul 22 09:31 test
-rw------- 1 u0_a87 u0_a87     160 Jul 22 09:31 test.zip
$ rm -rf test
$ unzip test.zip
Archive:  test.zip
$ unzip test.zip
Archive:  test.zip
$ ls -la
total 7300
drwx------ 3 u0_a87 u0_a87    4096 Jul 22 09:31 .
drwx------ 4 u0_a87 u0_a87    4096 Jul 22 09:13 ..
-rwxrwxrwx 1 u0_a87 u0_a87 7454766 Jul 22 01:24 Files.zip
drwx------ 2 u0_a87 u0_a87    4096 Jul 22 09:31 test
-rw------- 1 u0_a87 u0_a87     160 Jul 22 09:31 test.zip

What am I missing, how can I get access to that file from my user account without using su/sudo etc?

I also tried to find out if there are any extended attributes on that file. According to the internet ls -l would have shown me that there are extended attributes with a + character (e.g. -rwxrwxrwx+). As you can see above this was not the case. Just to be sure, I also checked using the attr command:

$ attr -l ./Files.zip
Attribute "selinux" has a 28 byte value for ./Files.zip
$ attr -g selinux ./Files.zip
attr_get: No data available
Could not get "selinux" for ./Files.zip
$ su -c attr -l ./Files.zip
sush: attr: not found
$ su -c attr -g selinux ./Files.zip
sush: attr: not found

The results were unclear to me. I don't understand why it tells me there is an "selinux" attribute, but then refuses to give me the value and then when I try with su -c it does't even list the "selinux" attribute, not to mention that getting the value fails.

4
  • 1
    Im guessing this could be caused by extended attributes. But usually this is indicated with a + sign in the permissions. You could try to do ls -l@
    – Peter
    Commented Jul 22, 2017 at 8:26
  • ls: invalid option -- '@' I don't think that exists on Android. I also checked --help, couldn't find anything about extended attributes. From all I know ls -l automatically shows extended attributes if there are any. So I doubt that there are are any extended attributes on my files.
    – Forivin
    Commented Jul 22, 2017 at 9:17
  • What does unzip -l Files.zip and unzip -t Files.zip output?
    – Tigger
    Commented Dec 28, 2017 at 6:14
  • Usually weird permissions issues are down to SELinux - try ls -lZ
    – symcbean
    Commented Sep 1, 2021 at 21:07

2 Answers 2

1

I'm had the exact same problem. While I don't understand what exactly is happening here, the workaround is to not use a separate file explorer to copy the files. Instead make sure that termux has the relevant android permissions (settings -> apps -> permissions; and/or execute termux-setup-storage).

In your termux home folder should be another folder called storage, which symlinks to your sdcard.

0

I have android 7x - as root: restorecon copy_of_file.db

I had the same problem and got the same result detailed in the question. The termux wiki gives enough clues to solve this: you need to be able to run restorecon (as root, in this case, tsudo).

https://wiki.termux.com/wiki/FAQ

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .