4

When we enable USB Debugging, there is automatically a popup that asks whether you want to authorize the PC to access the phone via USB Debugging. How do I enable it without the popup? Is there a command line query using which I can say "no prompt" or something like that?

Here is an image of the popup I am referring to:

screenshot

Thanks for the help.

10
  • 1
    Tick the checkbox, and the next time you connect to the very same computer there won't be a popup. That's a security measure so "Mr. Hacker" cannot simply adb pull content from your device.
    – Izzy
    Commented Nov 2, 2017 at 7:32
  • I want a command to allow this device by default. No touches on the screen.
    – Zac
    Commented Nov 2, 2017 at 18:09
  • So whatever computer it connects to, it should be allowed by default – despite of the implicated security risk? Not sure if that's possible, especially on a non-rooted device. Besides: those two "touches" have to be applied only on the first connection to a "new" computer – but I guess that was clear from the description on the checkbox.
    – Izzy
    Commented Nov 2, 2017 at 18:13
  • I understand that, I am basically looking for a command like --rsa_id=xyz that I can pass to authenticate in one step without touch. (For scripting purposes). Isn't my question or explanation clear?
    – Zac
    Commented Nov 2, 2017 at 18:47
  • What you want to achieve is clear, however the confirmation is a critical protection mechanism preventing lost phones from being hacked. Is the used ROM a custom ROM or is there an custom app with root permissions running on the phone?
    – Robert
    Commented Nov 2, 2017 at 19:47

1 Answer 1

2

The reason

This is deliberately omitted from production Android. If it was allowed, it would be trivial to read the contents of a lost or stolen phone. Since many people keep much of their lives on their phone, this would be a huge security problem.

As it is, someone who obtains a phone that belongs to someone else has to get through the screen lock (PIN, pattern, fingerprint, etc.) before they can enable USB debugging. If they can get through the screen lock, they can use the phone and its apps anyway, and the ability to enable USB debugging does not make things much worse.

A possible solution for an individual

If you enable developer mode and USB debugging, then authorise a computer with the pop-up, you can check the box "Always allow from this computer" and then the phone will connect to adb as soon as you plug it in. With more recent versions of Android than the 7.1 in the question, you should turn on "Disable adb authorisation timeout" in Settings => Developer Options if you want authorisation to persist longer than a week.

You can enable that for all your computers individually. Alternatively, you can enable it for any computer that you can copy a few files onto. This is a bit more of a risk, but it may suit the OP's needs.

The .android directory and its contents

The information that an Android device uses to recognise a host computer isn't a built-in part of the host. Instead, it is created by adb when you first run it on the host. In your user directory, you'll find a directory called .android. If you copy that directory and its contents to another computer where adb has never been run, and then install and run adb, the two computers will be treated by the device as being the same computer.

On Windows

You should use the Command Prompt for this. If you don't know how to use that, learn: it's basic technical computing, and if you can't learn this, you should not be tinkering with Android USB debugging.

In the command prompt:

C:\> echo %USERPROFILE%
C:\Users\ExampleUser
C:\>dir %USERPROFILE%
 Volume in drive C is Local Disk
 Volume Serial Number is Q8P4-Q7KQ
 Directory of C:\Users\ExampleUser

 22/07/2023  15:51    <DIR>          .
 12/10/2023  06:47    <DIR>          ..
 08/06/2023  20:19    <DIR>          .android
 ...
 28/08/2023  15:37    <DIR>          Desktop
 16/10/2023  03:21    <DIR>          Documents
 17/10/2023  14:58    <DIR>          Downloads
 ... 
                0 File(s)              0 bytes
               14 Dir(s)  373,509,562,890 bytes free

Copy the .android directory and its contents to the corresponding place on another computer. Provided you keep this data safe, you can use it to authorise any future computer, even one you don't have yet.

On Linux or macOS

In the shell:

ls -ald ~/.android

Other solutions

Extremely custom ROMs

If you're willing to rebuild Lineage OS from source, you should be able to build it with USB debugging pre-enabled and then flash a Lineage OS supported device with it. However, using such a device as your personal device would be silly: if you lost it, it's trivial for someone to get into it.

Devices that come pre-enabled for USB debugging

For completeness, there are devices that can run Android that come pre-enabled for USB debugging. However, they are not phones or tablets that you'd want to carry around. They're single-board computers, a bit like Raspberry Pis, designed for doing heavy-duty hardware or software development. They're intended to live in labs, not to be personal devices.

Non-solutions

Termux has no reference to doing this in its wiki.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .