Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

@aiamuzz
Copy link

aiamuzz commented Sep 3, 2019

@varhub ... thanks your instructions helped me enable adb via recovery
any possibility of adding wifi AP via recovery ?
You see i have newly flashed a custom rom ... and i am unable to access as my device screen isn't working ... the phone however is booting up ... i would like to inject my wifi AP details so the device connects to my wifi network on boot ...

Let me tell you that if you already enabled ADB you can use this tool to interact with your phone, and enable wifi AP if you want...

yup ... i am using that tool already ... but seems the screen problem on my device is not letting me access my phone freely ...

and i wanted to test your wireless adb ... hence i would like to know if there was a way i could push the wifi AP to my device through normal adb(not recovery adb) ... 😄

@samthelion17
Copy link

samthelion17 commented Sep 4, 2019

@varhub ... thanks your instructions helped me enable adb via recovery
any possibility of adding wifi AP via recovery ?
You see i have newly flashed a custom rom ... and i am unable to access as my device screen isn't working ... the phone however is booting up ... i would like to inject my wifi AP details so the device connects to my wifi network on boot ...

Let me tell you that if you already enabled ADB you can use this tool to interact with your phone, and enable wifi AP if you want...

yup ... i am using that tool already ... but seems the screen problem on my device is not letting me access my phone freely ...

and i wanted to test your wireless adb ... hence i would like to know if there was a way i could push the wifi AP to my device through normal adb(not recovery adb) ... smile

in that case you can try this although you might need different key combinations... wich can be found here

@aiamuzz
Copy link

aiamuzz commented Sep 4, 2019

in that case you can try this although you might need different key combinations... wich can be found here

thanks ... i managed to connect to my wifi using scrcpy ... took some time as it was laggy due to the screen issues my device had.

This is what i did:

-After adding "service.adb.tcp.port=5555" to /system/build.prop rebooted my phone, went to Settings/Developer options and swiped up down to ADB over Network, wich is now enabled permanently, and there is the IP address, but i assume you can get it on the console too.
-Next, on the computer, open a terminal and type "adb connect <IP_of_the_Phone:5555>"
-And you should see your device listed when typing "adb devices"

thanks @SamTheLion ... i was able to modify the build.prop and get the device to connect adb over the wireless network ...

@sreekar
Copy link

sreekar commented Oct 25, 2019

how to set adb vendor keys in redmi 5 plus

@andronoob
Copy link

andronoob commented Feb 26, 2020

I got adb working to debug in a bootloop situation.
https://gist.github.com/gregor160300/068c06c0314c19855e999473708c7635
Ubuntu provides the abootimg utility to modify boot.img. However, after unpacking initrd, I found that /default.prop was a symlink pointing to /system/etc/prop.default. After editing this file & reboot, I finally got adb working.

Related lines:

ro.secure=0
ro.debuggable=1
persist.sys.usb.config=adb
ro.adb.secure=0

@khadsevivek
Copy link

khadsevivek commented Apr 7, 2020

brp I didn't find out and edit the filepersist.sys.usb.config please help

@khadsevivek
Copy link

khadsevivek commented Apr 7, 2020

brp I didn't find out and edit the filepersist.sys.usb.config please help

@khadsevivek
Copy link

khadsevivek commented Apr 7, 2020

brp I didn't find out and edit the filepersist.sys.usb.config please help

@khadsevivek
Copy link

khadsevivek commented Apr 7, 2020

brp I didn't find out and edit the filepersist.sys.usb.config please help

@khadsevivek
Copy link

khadsevivek commented Apr 7, 2020

brp I didn't find out and edit the filepersist.sys.usb.config please help

@khadsevivek
Copy link

khadsevivek commented Apr 7, 2020

how to -> Now open that file in a texteditor and edit it to mtp,adb and save.

@pierluigicdc
Copy link

pierluigicdc commented Nov 3, 2020

Hi all,
i'm trying with a rom stock on mia2, but it seems not working... any ideas?

@caccamo88
Copy link

caccamo88 commented Apr 25, 2021

hi, just registered to thanks because worked like a charm and saved me literally (broken display, could not access to "2 factors authentication" apps like home banking, public identity etc!) With USB debugging enabled I could control my phone with computer software like Vysor.
(Lineage OS 14.1 Galaxy S4)

@clebig
Copy link

clebig commented Jun 11, 2021

Hey, thank you very much for these tips. I can confirm it still works with Android 11 crDroid 7.6.

@Lx0815
Copy link

Lx0815 commented Sep 10, 2021

brp I didn't find out and edit the filepersist.sys.usb.config please help
I'm very sorry to bother you, but has your problem been solved.I have the same problem as you

@samthelion17
Copy link

samthelion17 commented Sep 10, 2021

brp I didn't find out and edit the filepersist.sys.usb.config please help
I'm very sorry to bother you, but has your problem been solved.I have the same problem as you

If the file doesn't exist you just need to create it, with this command:
echo -n 'mtp,adb' > /data/property/persist.sys.usb.config
Just follow the instructions

@aryankaran
Copy link

aryankaran commented Nov 18, 2021

Thanks ..

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

This was what i was in need of ..

@anandharaj-dotworld
Copy link

anandharaj-dotworld commented Feb 21, 2022

Is possible to set a password for ADB connect?

@PaulLeger
Copy link

PaulLeger commented Apr 11, 2022

I recently broke the screen on my Galaxy S5 (klte) which runs LineageOS 18.1. I can see that the phone is connected with adb devices. When I try adb shell mount data I get the error of "mount: can't read '/etc/fstab': No such file or directory". I did a adb shell ls -R / >tree.txt and took a look in it. Under "/etc" there's only "mke2fs.conf" and "recovery.fstab". "/data" seems to be empty. I don't have a clue how to move on from here. Does anyone have an idea?

@gratuxri
Copy link

gratuxri commented Apr 12, 2022

Do you have root shell on your S5? If so, you can try to make dumps to sdcard: dd if=/dev/block/??? of=/sdcard/ bs=4096
Or just try odin dump, you can find it in your favorite search engine. Another way is to make sideload with root shell image.

@PaulLeger
Copy link

PaulLeger commented Apr 13, 2022

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

samthelion17 commented Apr 13, 2022

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.

@PaulLeger
Copy link

PaulLeger commented Apr 14, 2022

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

@gratuxri
Copy link

gratuxri commented Apr 15, 2022

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

@PaulLeger
Copy link

PaulLeger commented Apr 21, 2022

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?

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