My device is running Android 8.0, rooted using Magisk as the su
manager. I log into it using SimpleSSHD.
I'm trying to do some actions which require root access, and in the process I'm creating some files to be later used by normal users. But for some reason what I'm used to in "classical" Linux distributions doesn't appear to work: root-created files can't be read by normal users, whatever chown
/chgrp
/chmod
actions I try. See the following session:
$ su -c "echo hello > file.txt; chown $(whoami) file.txt; chgrp $(whoami) file.txt; chmod a+r file.txt"
$ cat file.txt
cat: file.txt: Permission denied
$ echo readable > my.txt
$ su -c 'cp -a my.txt my-copy.txt'
$ cat my-copy.txt
cat: my-copy.txt: Permission denied
$ ls -l *.txt
-rw-r--r-- 1 u0_a182 u0_a182 6 2018-08-20 15:21 file.txt
-rw------- 1 u0_a182 u0_a182 9 2018-08-20 15:23 my-copy.txt
-rw------- 1 u0_a182 u0_a182 9 2018-08-20 15:22 my.txt
$ whoami
u0_a182
What's happening here? Why are permission bits, owner and group ignored for files I created as root? How to properly change owner to normal user?