Why do I get access denied to data folder when using adb?

Viewed 379370

I connected to my live device using the adb and the following commands:

C:\>adb -s HT829GZ52000 shell
$ ls
ls
sqlite_stmt_journals
cache
sdcard
etc
system
sys
sbin
proc
logo.rle
init.trout.rc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
$ cd data
cd data
$ ls
ls
opendir failed, Permission denied

I was surprised to see that I have access denied. How come I can't browse around the directories using the commandline like this?

How do I get root access on my phone?

16 Answers

There are two things to remember if you want to browse everything on your device.

  1. You need to have a phone with root access in order to browse the data folder on an Android phone. That means either you have a developer device (ADP1 or an ION from Google I/O) or you've found a way to 'root' your phone some other way.
  2. You need to be running ADB in root mode, do this by executing: adb root

I had a similar problem when trying to operate on a rooted Samsung Galaxy S. Issuing a command from the computer shell

> adb root

fails with a message "cannot run as root in production builds". Here is a simple method that allows to become root.

Instead of the previous, issue the following two commands one after the other

> adb shell
$ su

After the first command, if the prompt has changed from '>' to '$' as shown above, it means that you have entered the adb shell environment. If subsequently the prompt has changed to '#' after issuing the second command, that means that you are now root. Now, as root, you can do anything you want with your device.

To switch back to 'safe' shell, issue

# exit

You will see that the prompt '$' reappears which means you are in the adb shell as a user and not as root.

This works if your Android device is rooted by any means (not sure if it works for non-rooted).

  1. adb shell - access the shell
  2. su - become the superuser.

You can now read all files in all directories.

production builds can't enter /data/app

drwxrwx--- system   cache             1970-01-01 08:00 cache
drwxrwxr-x root     system            1970-01-01 08:00 mnt 
drwxrwx--x system   system            1970-01-01 08:15 data

might need change to right owner to operate it.

if you know the application package you can cd directly to that folder..

eg cd data/data/com.yourapp

this will drop you into a directory that is read/writable so you can change files as needed. Since the folder is the same on the emulator, you can use that to get the folder path.

  1. You phone should be rooted. This is an important step!
  2. Go to the adb file location and start command prompt as an admin on that location
  3. run below commands: adb shell run-as com.domain.yourapp this will ask root access on your phone, allow it.
  4. You will be able to browse files using root access. Thanks!

I know this thread is pretty old but I encountered this problem today while trying to copy my database files from within android studio to my windows to read it. I didn't need to run any commands, in fact nothing at all in that manner. Only thing I did was reconnect the USB plugged to my device and when the prompt that says "use USB for" came up, I selected "file transfer" and it worked! No need for you to have a rooted device to copy its inner files.

Related