Skip to content

Instantly share code, notes, and snippets.

@varhub
Created December 23, 2016 17:54
Show Gist options
  • Save varhub/7b9555cdd1e5ad785ffde2300fcfd0bd to your computer and use it in GitHub Desktop.
Save varhub/7b9555cdd1e5ad785ffde2300fcfd0bd to your computer and use it in GitHub Desktop.
Android - Enable ADB from recovery

Android - Enable ADB from recovery

Credits to @TheOnlyAnil-@Firelord1

  • Requirements: a) stock recovery + rooted phone b) custom recovery

  • Files changed:

    • /system/build.prop
    • /data/property/persist.sys.usb.config
    • /data/misc/adb/adb_keys

Enable ADB (1/2): enable USB debugging

same as "Settings >> Developer Opcions >> USB debugging" ON

  • Connect the device to Mac or PC in recovery mode.
  • Now open terminal/CMD in computer and go to platform-tools/. type and enter adb devices to check if the device is connected in recovery mode.
  • Now type adb shell mount data and adb shell mount system to mount the respective directories.
  • Get the persist.sys.usb.config file in your system using adb pull /data/property/persist.sys.usb.config /Your directory
  • Now open that file in a texteditor and edit it to mtp,adb and save.
  • Now push the file back in the device; adb push /your-directory/persist.sys.usb.config /data/property
  • Get the build.prop file; adb pull /system/build.prop /your-directory
  • Add these lines:
persist.service.adb.enable=1                                                    
persist.service.debuggable=1
persist.sys.usb.config=mtp,adb
  • Push build.prop back into the device; adb push /your-dir/build.prop /system/

Fast way

adb shell
mount data
echo -n 'mtp,adb' > /data/property/persist.sys.usb.config

Verify options are not present before do it: adb shell "grep 'persist.service.adb.enable' /system/build.prop"

adb shell
mount system
echo '' >> /system/build.prop
echo '# Enable ADB' >> /system/build.prop
echo 'persist.service.adb.enable=1' >> /system/build.prop 
echo 'persist.service.debuggable=1' >> /system/build.prop
echo 'persist.sys.usb.config=mtp,adb' >> /system/build.prop 

Enable ADB (2/2): RSA verification

For the RSA verification that you asked to bypass, I don't know whether it would work in your device, but it worked in my little experiment. In Lollipop, the ADB keys (after authorization) are saved in /data/misc/adb/adb_keys. Your private key is saved in computer. In Linux the directory location is $HOME/.android/. On Windows that usually translates to %USERPROFILE%.android, but keys might end up in C:\Windows\System32\config\systemprofile.android in some cases.

adb push ~/.android/adbkey.pub /data/misc/adb/adb_keys

Bibliography

Footnotes

  1. http://android.stackexchange.com/questions/120394/can-i-enable-usb-debugging-using-adb

@JoKowski
Copy link

I guess so: adb shell whoami is answered with "root". I'm not sure if I understand you correctly. I want to enable usb debugging to use scrcpy to mirror the screen. Will I dump the respective files if I try your way? (Sorry! Newbie here.)

@samthelion17
Copy link

I guess so: adb shell whoami is answered with "root". I'm not sure if I understand you correctly. I want to enable usb debugging to use scrcpy to mirror the screen. Will I dump the respective files if I try your way? (Sorry! Newbie here.)

Buddy, if you are able to run adb commands you've successfully enabled usb debugging! Just run scrcpy as it is.

@JoKowski
Copy link

I get

C:\WINDOWS\system32>scrcpy
scrcpy 1.22 <https://github.com/Genymobile/scrcpy>
C:\scrcpy-win64-v1.23\scrcpy-server.jar: 1 file pushed, 0 skipped. 36.4 MB/s (41123 bytes in 0.001s)
/sbin/sh: app_process: not found
ERROR: Server connection failed

I also checked adb shell ls /system/bin/app_* and adb shell ls /vendor/bin/app_* getting "no such file or directory".

@samthelion17
Copy link

samthelion17 commented Apr 15, 2022 via email

@gratuxri
Copy link

I don't have S5, so I don't know exactly your paths. Can you try please somethink like mount /dev/block/data /data/ ?

@JoKowski
Copy link

I appreciate all of your help :) I've taken the easy way and bought an old device with a working touchscreen to change it.

@emkovic
Copy link

emkovic commented May 30, 2022

"adb shell mount data" gives me "error: device unauthorized."
I can't seem to bypass the RSA verification

"adb push ~/.android/adbkey.pub /data/misc/adb/adb_keys"
gives "adb: error: failed to get feature set: device unauthorized."

@anandharaj-dotworld
Copy link

anandharaj-dotworld commented May 30, 2022

@emkovic use /data for mount.
mount -o rw,remount /data

@gabrc52
Copy link

gabrc52 commented Jun 8, 2022

I wasn't able to use this for newer Android versions but for older Android versions it works (edit: I tried versions 6 through 10 and they all work). To mount system on the latest TWRP I used

twrp mount system
twrp mountrw

since mount system doesn't work. I guess a more UNIX/Linux-y longer mount command could've worked too.

@gabrc52
Copy link

gabrc52 commented Jun 16, 2022

Okay, it seems like if I do this on a clean install, it works. However, if I do the whole tap 10 times thing to enable developer options, then disable them, ADB stops working. Maybe this is why my previous attempts weren't working, since ADB had been explicitly turned off in other parts of Android. How would we change this using ADB/TWRP?

@ayandebnath
Copy link

You're a lifesaver.
Thanks.

@TipzRickyCheung
Copy link

TipzRickyCheung commented Oct 30, 2022

Alternative method to not have to modify /system/build.prop:

echo 'persist.service.adb.enable=1' >> /data/property/persistent_properties
echo 'persist.service.debuggable=1' >> /data/property/persistent_properties
echo 'persist.sys.usb.config=mtp,adb' >> /data/property/persistent_properties

@ffpp2003
Copy link

I appear to have some troube with the instructions on my Samsung Galaxy S6 with LineageOS 17. It appear to be that build.prop is not present while in recovery mode. Probably it exists once the system is booted, but appearently not on the recovery. I anyway executed all the commands (i had to create the build.prop), but got no succes after booting the system.
Is there any other way to enable USB debugging?

@gabrc52
Copy link

gabrc52 commented Feb 14, 2023

Mount /system

@ffpp2003
Copy link

Mount /system

System is mounted. I can see all files, but there is no build.prop

@ffpp2003
Copy link

Problem solved. build.prop was located in /system/system

@SaiGuyGames
Copy link

Thanks I wasnt able to keep my phone on for a few seconds so I couldnt enable adb and now it fixed both problems

@datninjaWild
Copy link

ok what if your device isnt recognized? is there a way to ENABLE adb through download mode or revovery mode, adb devices would show?

@ValorNaram
Copy link

ValorNaram commented May 12, 2023

Problem solved. build.prop was located in /system/system

On LineageOS 20 I needed to do

mount -o rw,seclabel,relatime /dev/block/dm-1 /mnt/system

because mount system did not work.

And then

echo '' >> /mnt/system/system/build.prop
echo '# Enable ADB' >> /mnt/system/system/build.prop
echo 'persist.service.adb.enable=1' >> /mnt/system/system/build.prop 
echo 'persist.service.debuggable=1' >> /mnt/system/system/build.prop
echo 'persist.sys.usb.config=mtp,adb' >> /mnt/system/system/build.prop 

@SaiGuyGames
Copy link

@ValorNaram thats pretty smart but why am i still getting notified for this

@gabrc52
Copy link

gabrc52 commented May 12, 2023

I think you get notifications if you commented once

@char101
Copy link

char101 commented Jul 24, 2023

/system is twrp system. To mount android /system use mount /system_root.

@lexavey
Copy link

lexavey commented Jul 28, 2023

I create Magisk Module for this, check this out.
https://github.com/lexavey/Adb-Root-Enabler

@Jaspix
Copy link

Jaspix commented Oct 15, 2023

On LineageOS 20 I needed to do

How did you do the RSA verification? Isn't the /data partition encrypted by default on LineageOS 20?

@kazakovDanil1
Copy link

hello guys, i make first file inside data/property/persist.sys.usb.config >> "mtp, adb"

next add inside /system_root/system/build.prop >>

"persist.service.adb.enable=1
persist.service.debuggable=1
persist.sys.usb.config=mtp,adb"

as i understand right now my phone should receive adb commands from terminal , but it's not. Why?

i tries to enter ./adb command

/system/bin/sh: appops: inaccessible or not found

android 14

i'm on the galaxy s23+

who did this on newer phones?

@lexavey
Copy link

lexavey commented Dec 14, 2023

hello guys, i make first file inside data/property/persist.sys.usb.config >> "mtp, adb"

next add inside /system_root/system/build.prop >>

"persist.service.adb.enable=1 persist.service.debuggable=1 persist.sys.usb.config=mtp,adb"

as i understand right now my phone should receive adb commands from terminal , but it's not. Why?

i tries to enter ./adb command

/system/bin/sh: appops: inaccessible or not found

android 14

i'm on the galaxy s23+

who did this on newer phones?

are you able to connect adb ? confirmed with adb devices and your device listed ?
if not, i think your problem in android.

if you cant execute adb devices then your problem is in your pc.

@nift4
Copy link

nift4 commented Jan 23, 2024

adb shell rm /data/property/persistent_properties instead of (or in addition to) echo -n 'mtp,adb' > /data/property/persist.sys.usb.config worked for me

@BobWidlar
Copy link

I create Magisk Module for this, check this out. https://github.com/lexavey/Adb-Root-Enabler

Hi guys, I am on lineageos 9. I managed to get usb debugging enabled through twrp, but I can't seem to bypass the RSA verification even though I have copied the key as mentioned above. Unfortunately, I don't have magisk installed, but is there a way to install the unauthorized adb manually through twrp?

@io2345
Copy link

io2345 commented Mar 20, 2024

Thanks to all, especially the threadstarter for the idea. And a special thanks to @nift4 for the final trick with deleting or renaming the persistent_properties. That did the trick finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment