2

Why would I get permission denied using adb to copy a directory to a subdirectory on my phone, when I could copy to its parent directory and both have the same permission?

I tried this from my PC to my Nexus 5 running 6.0.1 (Oct 5):

adb push Dir /sdcard/Dir/Subdir

It failed with

Permission denied

This has worked before, with no changes I'm aware of.

I launched adb shell and ran

ls -l

to get permissions for /sdcard (storage/emulated/0), /sdcard/Dir and /sdcard/Dir/Subdir:

drwxrwx--x root sdcard_rw

I then:

cd /sdcard/Dir/Subdir
mkdir XYZ

Got

mdkdir: XYZ: Permission Denied

Tried:

su
mkdir XYZ

Again, permission denied

I then tried another push

adb push XYZ /sdcard/Dir

This worked and copied all of the files.

Why would it work to /sdcard/Dir and not to /sdcard/Dir/Subdir, when both have the same permissions? Why would permission be denied for root?

5
  • 1
    Did you create that subdir when browsed into /data/media/0/Dir/? Either way, please provide the output of su -c 'ls -l /data/media/0/Dir/Subdir' and compare the permissions with the rest of the subdirs there.
    – Firelord
    Oct 14, 2016 at 12:18
  • @Firelord I did not create the subdirectry when browsed there. The entire directory tree (/sdcard/Dir) was created by an adb push. Permissions for Dir are dwrxrwxr-x media_rw media_rw, while Subdir are dwrxrwxr-x root root. When using plain ls -l on storage/emulated/0, I get dwrxrwx--x root sdcard_rw on Dir?
    – foosion
    Oct 14, 2016 at 13:39
  • 1
    Could you change the permission of /data/media/0/Dir/Subdir to rwxrwxrwx, or alternatively, change the user group from root to media_rw? Make sure to run the operations on the /data/media/0/.. path and no /storage/emulated/..
    – Firelord
    Oct 14, 2016 at 14:14
  • @Firelord That worked (chmod 777). Thank you. What's the difference between /data/media/0 and /storage/emulated or /sdcard? The each appear to contain the same files?
    – foosion
    Oct 14, 2016 at 17:32
  • /data/media is the real path in EXT4 filesystem. /storage hosts the FAT style emulated /data/media which you and the apps can read and write into. I do not know the reason behind this emulation.
    – Firelord
    Oct 15, 2016 at 3:53

2 Answers 2

1

As it appears in this comment, the file permissions and access control to SubDir differs from what ideally should be.

The problem:

# ls -l on /data/media/0/Dir
dwrxrwxr-x root root

The user group should have been media_rw instead of root.

The solution is to change to appropriate group or make the directory writable by others.

chmod 777 /data/media/0/Dir/SubDir       # making SubDir writable by others
chgrp media_rw /data/media/0/Dir/SubDir  # Alternatively, changing group from root to media_rw

Note: you may need to install Busybox or Toybox to have and use chmod and/or chgrp.

0

There's a similar problem reported in adb push ... Permission denied where I ended up pushing the file to /sdcard/ and then used adb shell to then copy the file to the sub-directory I needed it to be in.

For completeness:

Let's assume I have an expansion file test.obb file I want to install on a local physical Android device, and my package name of the app is app.example.test.

I pushed the file using adb push e.g. adb push test.obb /sdcard/

adb shell

cd /sdcard/Android/obb/app.example.test/
cp /sdcard/test.obb .
ls -la

I can now see the obb file is in the folder it needs to be in.

You must log in to answer this question.

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