Error Code: error: permission denied / Operation not permitted

How to Fix "Permission Denied" in ADB Shell

Understand Android Linux permission sandboxes, SELinux policies, and non-root limits.

Common Symptoms

  • Commands accessing `/data/data/` or `/system` fail with "Permission denied"

Root Causes

  • The shell user (UID 2000) does not have read/write access to private app sandboxes without root or `run-as`
  • SELinux enforcing policy blocks access to privileged kernel subsystems

Proven Solutions

Solution 1: Use "run-as" for Debuggable Applications

  1. If you developed the app and it has `android:debuggable="true"` in AndroidManifest.xml:
  2. Run `adb shell run-as com.your.package`
  3. You will be placed directly inside `/data/data/com.your.package` with full read/write permissions!
adb shell run-as <package-name>

Solution 2: Use AppOps for System Settings

Grant WRITE_SECURE_SETTINGS or AppOps overrides via ADB shell commands.

adb shell pm grant <package> android.permission.WRITE_SECURE_SETTINGS