61

When I'm using a rooted Android device as ADB host to send adb command "adb devices" to Samsung S4, I received device unauthorized error message. However when I tried adb to Samsung Galaxy Nexus, it is working fine. Can anyone advise how to solve my Samsung S4 problem?

=========================================
# adb devices
List of devices attached
4d00f9169907301b        unauthorized
=========================================

Edit: Found that this problem only happened to Android 4.2.2 and above. The following link explained that Google has implemented some new security features for using adb.

http://nelenkov.blogspot.com/2013/02/secure-usb-debugging-in-android-422.html

Appreciate if anyone can help on this.

starball
  • 20,030
  • 7
  • 43
  • 238
Kong Ken
  • 3,859
  • 2
  • 15
  • 14

15 Answers15

71
  • Get the public key from the client phone (adb host)

    cat /data/.android/adbkey.pub

  • copy the above public key to the target phone's /data/misc/adb/adb_keys location. (you may need to stop the adb daemon first with stop adbd)

    cat /data/misc/adb/adb_keys

verify both cat outputs match.

try restarting adb daemon on target start adbd or just reboot them.

If you are having problems reading or writing to ADB KEYS in above steps, try setting environment variable ADB_KEYS_PATH with a temporary path (eg: /data/local/tmp). Refer to that link it goes into more details

    "On the host, the user public/private key pair is automatically generated,
    if it does not exist, when the adb daemon starts and is stored in
    $HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
    the ADB_KEYS_PATH env variable may be set to a :-separated (; under
    Windows) list of private keys, e.g. company-wide or vendor keys.

    On the device, vendors public keys are installed at build time in
    /adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys"
ashoke
  • 6,441
  • 2
  • 26
  • 25
  • This advice helped me to connect from my laptop's ADB to my phone! It would not connect no matter what, but this solution works. So this can be helpful not only for host phones, but also for host PCs. The only difference was to find adbkey.pub on my system, which was located at ```/home/myuser/.android/adbkey.pub``` – afrish Feb 12 '19 at 07:57
  • 1
    How do I copy the file to the target phone? If I try `cat /data/misc/adb/adb_keys` or even `cd /data/` I get `No such file or directory`. – Kajsa Apr 05 '19 at 12:48
  • how to do it on Windows? – user924 Dec 24 '20 at 00:40
  • 4
    1. copy the `~/.android/adbkey.pub` file with ssh to `/data/misc/adb/adb_keys`. 2. issue commands on device: `chmod 0640 /data/misc/adb/adb_keys`; `chown system:shell /data/misc/adb/adb_keys`, `chcon u:object_r:adb_keys_file:s0 /data/misc/adb/adb_keys`; `start adbd` and finally it worked with default, untouched adb on host – grandrew Jul 23 '21 at 05:28
  • @grandrew I tried that steps with no luck on Android 4.4.2 (rooted) all commands passed with no errors and `cat adbkey.pub` is matching on that on PC but it still asking for auentication. – Mamdouh Saeed Dec 13 '22 at 08:03
  • This solution worked for me (android x86 7.1 LineageOS 14.1 running on vmware). After copying the pubkey file to (must gain access root first) to the cited folder I was able to deploy and run my app in VM! Thanks! – digfish Dec 25 '22 at 16:52
50

Check and uncheck the USB Debugging option in the device. If that doesn't work unplug and plug in the USB a couple of times.

At some point, the device should show a message box to ask you to authorize the computer. Click yes and then the device will be authorized.

Prasanth Louis
  • 4,658
  • 2
  • 34
  • 47
  • 2
    This helped me, did this while the device was plugged in and I got a pop-up on my phone asking if I wanted to trust the PC, said always trust and now I can access it via adb – Steve Aug 10 '16 at 21:49
  • 3
    I had to do `adb kill-server` on my computer. Then unplugged the usb cable, waited 5 seconds, plugged it in and my phone asked my to *allow usb debugging*. I checked *OK* and then it worked (the word *unauthorized* was gone). – erik Sep 08 '17 at 14:48
33

If anyone has similar issue of having a phone with a cracked screen and has a need to access adb:

  1. Root your phone (mine was already rooted, so I was blessed at least with that).

If you forgot to enable developers mode and your adb isn't running, then do the following:

  1. Reboot your phone into recovery.
  2. Connect the phone with a cable.
  3. Open terminal.
  4. If you type adb devices you should see the device in the list.
  5. If so, type:

    adb shell mount /system
    abd shell
    
    echo "persist.service.adb.enable=1" >> default.prop 
    echo "persist.service.debuggable=1" >> default.prop
    echo "persist.sys.usb.config=mtp,adb" >> default.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
    

Now if you are going to reboot into your phone android will tell you "oh your adb is working but please tap on this OK button, so we can trust your PC". And obviously if we can't tap on the phone stay in the recovery mode and do the following (assuming you are not in the adb shell mode, if so first type exit):

cd ~/.android
adb push adbkey.pub /data/misc/adb/adb_keys
  1. Hurray, it all should be hunky-dory now! Just reboot the phone and you should be able to access adb when the phone is running:

    adb shell reboot

P.S. Was using OS X and Moto X Style that's with the cracked screen.

kiradotee
  • 1,205
  • 12
  • 20
  • 1
    `adb shell reboot` `adb kill-server` `adb shell` Commands in this order helped. – Gelldur Jun 18 '17 at 09:15
  • @SifaturRahman Not sure what you mean by terminal emulator. You should be able to use adb from Terminal.app on macOS and from cmd.exe on Windows. Though, obviously, in both cases you need to download and install whatever is needed for adb to work on your OS. – kiradotee Mar 11 '18 at 14:00
  • I got to the point where my device is listed as "host". However, any adb command I send returns "error: closed". How can I get pass this point? – Daniel Reina Oct 01 '22 at 18:08
12

Have you tried

adb kill-server
adb shell

Sometimes adb gets stuck and first killing adb server and then starting some command forces authorization window to pop-up.

Also please check adb client version on your phone. THis feature is supported from adb 1.0.31 as far as I remember.

Tomasz Szuba
  • 905
  • 4
  • 14
8

Experience With: ASUS ZENFONE

If at all you have faced Missing Driver for Asus Zenfones Follow This Link (http://donandroid.com/how-to-install-adb-interface-drivers-windows-7-xp-vista-623)

I tried with

1) Killing and starting adb server at adb cmd.

2) Switching Usb Debugging on and Off and ...

This is What WORKED with me.

Step 1:Remove Connection with Device and Close Eclipse

Step 2:Navigate to C:/Users/User_name/.android/

Step 3:You Will Find adb_key

Step 4:Just delete it.

Step 5.Connect again and System will ask you Again.

Step 6.Ask Device to remember RSA Key when it Prompts. I think its done.

If you Face The Same Problem after couple of days, just disable and enable USB debugging

Karthik Sagar
  • 424
  • 4
  • 7
7

For unknown reasons, I only had ~/.android/adbkey, but not ~/.android/adbkey.pub.

I guess that adb was unable to push the public key to the device, and thus the device could never show the authorization dialog.

After killing the adb server, removing the adbkey file and starting adb again, the authorization dialog popped up on the phone.

cweiske
  • 30,033
  • 14
  • 133
  • 194
6

Try this steps:

  1. unplug device
  2. adb kill-server
  3. adb start-server
  4. plug device

You need to allow Allow USB debugging in your device when popup.

Mritunjay Upadhyay
  • 1,004
  • 1
  • 15
  • 27
1

You need to allow Allow USB debugging when the popup shows up when you first connect to the computer!

Tan Dat
  • 2,888
  • 1
  • 17
  • 39
0

Delete the folder .android from C:/users/<user name>/.android. It solved the issue for me.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
0

I had to check the box for the debugger on the phone "always allow on this phone". I then did a adb devices and then entered the adb command to clear the adds. It worked fine. Before that, it did not recognize the pm and other commands

0

For me, the emulator could not have Google Play Services enabled. It could have Google APIs or be x86 or x64 but not google play store.

valdetero
  • 4,624
  • 1
  • 31
  • 46
0

Try a USB2 port if you're plugged into a USB3 port. At least through the Pixel3 line this makes a difference. Many people have observed the same problem but I'm not sure if anybody knows why. Perhaps there's a way to tell the kernel to not do something USB3-ish on the USB port that the phones can't handle.

I got here because I forgot this workaround, found this page, then remembered to use the other port.

Bill McGonigle
  • 215
  • 1
  • 9
0

Please follow following steps :

  1. Unplug your phone from system
  2. Go to developer options of the Cellphone and then click on "Allow USB debugging" then please select the radio button prompting "Allow USB debugging when the popup shows up when you first connect to the computer!".....

That's it.. run your command again :

 adb devices
Ash
  • 5,525
  • 1
  • 40
  • 34
-1

You must be prompted in your s4 screen to authorize that computer. You can tell it to remember it. This is for security reasons, occurring in Android 4.4+

webo80
  • 3,365
  • 5
  • 35
  • 52
  • Thanks webo80. ADB from computer is working fine. But my problem is when i'm trying to send ADB command from a Android phone's terminal. – Kong Ken Oct 06 '14 at 10:13
  • @KongKen So wait a second - are you trying to connect a phone with another phone through ADB? You mean through OTG or wireless ADB? If so - that's a very interesting endeavor... BTW, the developer options are enabled on the phone that needs to receive the commands, right? – Dev-iL Oct 06 '14 at 10:21
  • @Dev-iL yeah, I'm trying to connect two Android phones with OTA. – Kong Ken Oct 06 '14 at 10:22
  • hard to tell if you use adb shell from phone's terminal via OTG. Didn't know that adb was available on a phone used at "host" – webo80 Oct 06 '14 at 10:28
  • BTW, if the "host" phone exposes its RSA key, the "client" phone must prompt for authorization too, no? – webo80 Oct 06 '14 at 10:29
  • 2
    @KongKen A google search for [ADB between two phones OTG](https://www.google.com/search?q=ADB+between+two+phones+OTG) gives some relevant results (and similar questions on SO). Maybe [this article on XDA](http://forum.xda-developers.com/galaxy-nexus/general/guide-adb-connection-android-devices-t1935975) could help you. – Dev-iL Oct 06 '14 at 10:29
  • thanks @Dev-iL. Once of the article you shared talking about replace /system/bin/adb file in Android device but i still have no clue how to get a suitable adb file to replace it... – Kong Ken Oct 06 '14 at 11:09
-1

I found one solution with Nexus 5, and TWRP installed. Basically format was the only solution I found and I tried all solutions listed here before: ADB Android Device Unauthorized

Ask Google to make backup of your apps. Save all important files you may have on your phone

Please note that I decline all liability in case of failure as what I did was quite risky but worked in my case:

Enable USB debugging in developer option (not sure if it helped as device was unauthorized but still...)

Make sure your phone is connected to computer and you can access storage

Download google img of your nexus: https://developers.google.com/android/nexus/images unrar your files and places them in a new folder on your computer, name it factory (any name will do).

wipe ALL datas... you will have 0 file in your android accessed from computer.

Then reboot into BOOTLOADER mode... you will have the message "you have no OS installed are you sure you want to reboot ?"

Then execute (double click) the .bat file inside the "factory" folder.

You will see command line detailed installation of the OS. Of course avoid disconnecting cable during this phase...

Phone will take about 5mn to initialize.

Community
  • 1
  • 1
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81