4

I am already a member of the group "aid_sdcard_rw":

android@localhost:~$ whoami
android
android@localhost:~$ groups
android aid_radio ...... aid_sdcard_rw ......

you can see that i am already in group aid_sdcard_rw. Then, when i access directory /storage/sdcard0 :

android@localhost:~$ ls /storage/sdcard0/
ls: cannot open directory '/storage/sdcard0/': Permission denied

but:

android@localhost:~$ ls -l /storage/
total 8
d---rwxr-x 17 android aid_sdcard_rw 8192 1月   1  1970 sdcard0

doesn't group "aid_sdcard_rw" members have read permission? why is this Permission denied happened?


The system i run is an ubuntu 16.04 and running in my android phone using an app called Linux Deploy, and my phone have external sd card inserted :

Welcome to Ubuntu 16.04 LTS (GNU/Linux 3.4.5 armv7l)

 * Documentation:  https://help.ubuntu.com/
Ubuntu 16.04 LTS [running via Linux Deploy]

The directory /storage/sdcard0 is my external sd card mount directory(see the last line below):

android@localhost:~$ cat /etc/mtab
/dev/loop1 / ext4 rw,relatime,data=ordered 0 0
proc /proc proc rw,relatime 0 0
sys /sys sysfs rw,relatime 0 0
tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw,relatime 0 0
/dev/block/vold/179:97 /storage/sdcard0 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0

I have tried umount /storage/sdcard0 and remount it with option -o umask=0000 , but command ls -l /storage get same result as above.

7

If the user that owns the file or directory is explicitly denied access to the file or directory through the permissions, then that user can not access the file or directory. It does not matter if the owner is a member of the group that has access.

Or in other words, to access the file or directory as the owner, it has to allow access to the owner.

In your case, you have a directory without x permissions for the owner. The owner can therefore not access the directory.

To fix this, use

chmod u+x /storage/sdcard0

If the owner additionally needs to be able to list the contents of the directory, also give the owner r permissions. To create or delete files or subdirectories, you will need w permissions.

You should be able to set the permissions on the directory with the card unmounted. When mounting the SD card, the permissions on the mount point should be inherited from the directory permissions.

5

The android user is also the owner of the directory, owner that has no rights (even if android user is member of a valid group). The solution would be to change the owner of the directory with chown or try it with another user (that belongs to a valid group).

6
  • You first said "even if android user is member of a valid group". Why would it then change anything if it was a different user belonging to a valid group? Also, why change the owner of the directory, when OP is the owner of the directory? Also, as you can see, the "others" entity also has read and execute permissions, so anyone on that system should be able to read that directory. – Larry Jan 8 '19 at 13:00
  • 2
    @Larry because the file permission bits state that the owner does not have read, write or execute permissions on the directory. It seem like unusual permissions for the directory but that's what the permission bits are set to. A more suitable set of permissions would be 775 – Torin Jan 8 '19 at 13:22
  • @Torin: I see, thanks. But does chown also change the permissions that apply to the target user on the file? Otherwise, the other use will still be explicitly denied read permission. – Larry Jan 8 '19 at 14:21
  • 2
    @Larri: chown changes the owner and group of the file/directory but does not affect to the permissions; if the permissions are 075, after the execution of chown they will keep same, but the permision 0 will affect to the new owner instead of to the "old" one. – Dasel Jan 8 '19 at 14:28
  • 2
    @Larry chown-ing is one way to 'solve' the problem, but then the new owner has the issue that they can't access the directory (as long as they aren't root). chmod-ing would instead allow all users of the group, including the owner to have full permissions on the directory which is probably closer to solving it. – Torin Jan 8 '19 at 14:38
4

File permissions have a precedence order:

  • User permissions affect the owner of the file.
  • Group permissions affect everyone in the file's group.
  • Other permissions affect everyone else.

The permissions aren't merged -- they're tested in order. This means the group permissions don't affect the owner, and other permissions don't affect the owner and group. This then permits the situation where wider sets of users can have more permissions than more specific ones -- this is occasionally useful when you have a file or directory that should generally be accessible, but you want to exclude a specific user or group.

However, this is mostly ineffectual when it comes to excluding a user. The owner of a file also has permission to change its permissions, so the owner can do

chmod u+rwx /storage/sdcard0

However, if the user is in a restricted environment where they can't use chmod, this can be effective.

0

Try to execute like this:

newgrp aid_sdcard_rw 
ls /storage/sdcard0/
1
  • 2
    sorry, but this doesn't work. still get permission error. I guess @Dasel is right. when you are owner of an directory, then it will first apply that rule and ignore others. – zeyang yue Jan 8 '19 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.