124

Whatever I type after adb shell it fails with Permission denied:

D:\android-sdk-windows\platform-tools>adb shell find /data -name *.db
find: permission denied

D:\android-sdk-windows\platform-tools>adb shell test
test: permission denied

D:\android-sdk-windows\platform-tools>adb remount
remount failed: No such file or directory

Any ideas?

Yves M.
  • 29,855
  • 23
  • 108
  • 144
Caner
  • 57,267
  • 35
  • 174
  • 180
  • Where are you trying to run the adb shell, in emulator or target device; if on target device you cant access the /data folder until unless you have root permission. – Vamsi Sep 13 '11 at 08:56
  • 38
    after `adb root` >> `adbd cannot run as root in production builds` what to do? – d.popov Nov 14 '12 at 23:24
  • 3
    I guess you need a rooted phone to be able to run that – Caner Nov 15 '12 at 09:00
  • yes, I know. But, as you see currently I do not have the reputation to comment the Author's post, but i had this problem, so the only way was to add new post, or to open duplicate thread, so I decided to add a post. – d.popov Jan 02 '13 at 10:19
  • 1
    the phone is was rooted, but something went wrong with the OS. It was freezing after loading the home screen on reboot. Anyway - nandroid flashing the phone with the stock ROM solved the problem. – d.popov Jan 02 '13 at 10:23

10 Answers10

172

According to adb help:

adb root                     - restarts the adbd daemon with root permissions

Which indeed resolved the issue for me.

Roman
  • 1,880
  • 1
  • 13
  • 12
61

Without rooting: If you can't root your phone, use the run-as <package> command to be able to access data of your application.

Example:

$ adb exec-out run-as com.yourcompany.app ls -R /data/data/com.yourcompany.app/

exec-out executes the command without starting a shell and mangling the output.

Fabian Zeindl
  • 5,860
  • 8
  • 54
  • 78
  • 16
    This only works for apps built to be debuggable - ie, you can use it for apps you are developing but it should not work for production releases of your app, or anyone else's apps. – Chris Stratton Nov 24 '17 at 16:46
  • 3
    This returns `run-as: Could not set capabilities: Operation not permitted` for me – Tom M Jan 08 '19 at 15:34
  • 1
    It works for emulator API 29, and don't forget to put `.debug` prefix to the end of app's package for debug apps: – ultraon Aug 05 '20 at 21:59
  • I'm receiving: `run-as: package not an application: com.android.phone` – Ricky Levi Jul 13 '23 at 08:11
25

The reason for "permission denied" is because your Android machine has not been correctly rooted. Did you see $ after you started adb shell? If you correctly rooted your machine, you would have seen # instead.

If you see the $, try entering Super User mode by typing su. If Root is enabled, you will see the # - without asking for password.

wind
  • 275
  • 3
  • 2
6

You might need to activate adb root from the developer settings menu. If you run adb root from the cmd line you can get:

root access is disabled by system setting - enable in settings -> development options

Once you activate the root option (ADB only or Apps and ADB) adb will restart and you will be able to use root from the cmd line.

Macarse
  • 91,829
  • 44
  • 175
  • 230
  • 4
    If you can't see the 'Developer options' item in your Settings menu, see [this answer](http://stackoverflow.com/a/16866430/647939) for details of how to make it visible. (In short: Settings > About phone > Build number > Tap 7 times(!).) – Paul Whittaker Oct 20 '13 at 11:16
  • 1
    But once in, I don't see anything here! What should it say? – JohnyTex Oct 28 '14 at 14:00
  • 50
    **This option does not exist in stock Android builds** - if it exists at all, it would be confined to someone's aftermarket ROM. – Chris Stratton Nov 06 '14 at 18:14
  • Is there a way to do this without a GUI? I would guess there is an option for it in `/system/build.prop`, but I can't find it. – Jeroen Aug 16 '17 at 11:40
  • Where do I find the menu to look for settings? – martinkunev Dec 10 '17 at 16:34
6

None of the previous solutions worked for me but I was able to make it work using this command

adb shell "run-as com.yourcompany.app cat /data/data/com.yourcompany.app/shared_prefs/SHARED_PREF_PROTECTED.xml" > SHARED_PREF_PROTECTED.xml
Darien Alvarez
  • 153
  • 2
  • 10
  • This is great, however for binary files such as images or localDBs, the encoding seems to change. How would one copy binary files to windows? – raw May 14 '22 at 11:35
5

The data partition is not accessible for non-root users, if you want to access it you must root your phone.

ADB root does not work for all product and depend on phone build type.

in the new version of android studio, you can explore /data/data path for debuggable apps.

update 2022

Android Studio new versions have some tools like Device Explorer and App Inspection to access application data. (app must be debuggable).

Golil
  • 467
  • 4
  • 12
  • Confirm the```permission denied``` on Android emulator with API 30. I was working on getting on disk a sqlite file via ```$adb pull``` which also requires ```adb root``` – Gleichmut Oct 27 '22 at 13:49
  • you cannot directly access to data folder or DB location from ADB in non-rooted device. but you can use Android Studio tools like Device Explorer or App Inspection to access debuggable app data like SQLite DB. – Golil Oct 29 '22 at 04:26
  • `Device Explorer` worked for me, in Android Studio Chipmunk (2021.2.1) . I found my application files in `/data/data/com.mycompany.myapp/files`. I think this it equivalent to `adb run-as` because for other apps at the same level if I try to open the folder I get an error `run-as ...`. – Stephen Hosking Jul 11 '23 at 01:53
  • The app is built with Debug. The phone is a Nokia with Android 11 Go and not rooted (and not rootable, as with most modern phones.) – Stephen Hosking Jul 11 '23 at 01:54
1

if you are looking to get /data/anr/ as I was, you can use an easy approach

adb bugreport

source: this answer

Henrique Vasconcellos
  • 1,144
  • 1
  • 8
  • 13
-4

Do adb remount. And then try adb shell

Pavankumar Vijapur
  • 1,196
  • 2
  • 10
  • 15
-5

Solution for me was (thx to David Ljung Madison post)

  1. Root the phone & be sure it is rooted
  2. Adb server (adbd) was not run as root so downloaded & installed the adbd insecure app
  3. Restart adb adb kill-server
  4. Run it & worked like a flower!
Community
  • 1
  • 1
Pipo
  • 4,653
  • 38
  • 47
-8

Run your cmd as administrator this will solve my issues. Thanks.

Kishan Oza
  • 1,707
  • 1
  • 16
  • 38