How to Fix ADB Unauthorized Error

Android Robot

The Android Debug Bridge, aka adb, has been an indispensable tool while unlocking and rooting my new Moto G5 Plus. I’ve used it dozens of times this week to push and pull files, run shells, and reboot my phone. Today, as is my habit, I ran the command adb devices after plugging my phone into my laptop, but the response I received made it obvious that I had some troubleshooting ahead of me.

tpodlaski@Alabama:~adb devices List of devices attached * daemon not running. starting it now at tcp:5037 * * daemon started successfully * ZY2243PNMF      unauthorized</pre> The output of <span class="code">adb devices</span> lists the devices currently connected to your computer and recognized by the adb server. In addition to a unique identifier, the state of the device is also reported. Since I'd been using adb without issue for days, I fully expected to see the G5's state listed as <em>device</em>, meaning it is connected and ready to go. Instead it was <em>unauthorized</em>, a condition I would have to rectify before I could get any work done.  <span id="more-4112"></span>  If you aren't familiar with the ins and outs of connecting to your phone using adb, the <em>unauthorized</em> status might lead you to believe that your phone wasn't authorized to connect to your computer. It turns out the opposite is true. adb believes that your computer is not authorized to connect to your phone, a situation I knew not to be the case since I had successfully connected the two just earlier today.  Using adb is not as simple as just plugging in your phone, launching a terminal session, and having at it. Well, not the first time anyway. In order for the adb server to even recognize your device at all, you will have had to have enabled the hidden Developer Options settings and then made sure that USB Debugging was set to on. (For more on enabling Developer Options, see my post "<a href="">How to Enable Developer Options in Android 7 Nougat</a>."  The first time you connect your phone to your computer after activating USB Debugging, you'll get a pop up on your phone asking if you would like to authorize your computer to connect to it If you answer yes, the public key of your computer is stored on your phone. Unless you deauthorize your computer, any future connections between your phone and the computer will not require reauthorization.  This is how it should work, but I had not deauthorized my phone since the last time I used adb. I was not prompted to authorize the computer when I connected, and could not think of any reason to explain the <em>unauthorized</em> status.  I hit Google to find an answer, and while I was eventually able to fix the status, I am still clueless as to what caused the issue in the first place.  It turns out this is not an entirely uncommon problem, although the most common solutions were of no help to me. That said, if you are in a similar situation, it's probably worthwhile to try to the easy fixes first as they did seem to help the bulk of those looking for help. <h3>Possible solutions:</h3> <ol>  	<li><strong>Reboot the phone and the computer. </strong> [br] This one almost goes without saying. It's the first play in every troubleshooter's playbook. I didn't see that this method actually solved it for anyone, but it's still worth a shot.</li>  	<li><strong>Stop and restart the adb server.</strong> [br]Disconnect the device. [br]<span class="code">adb kill-server</span> [br] <span class="code">adb start-server</span> [br] Reconnect the device. [br] <span class="code">adb devices</span></li>  	<li><strong>Toggle USB Debugging off and back on.</strong> [br] Find the USB Debugging setting in the Developer Options and switch it off and back on again. [br] <img class="aligncenter size-medium wp-image-4097" src="" alt="Moto G5 Plus USB Debugging" width="300" height="189" /></li>  	<li><strong>Revoke USB Debugging Authorizations</strong> [br] In the Developer Options settings find  "Revoke USB Debugging Authorizations". [br] Click it to remove the keys of all authorized computers. [br] Reconnect the phone and you should be prompted to authorize the computer. [br]  [br] This solution was particularly troublesome for me because I do not have the Revoke USB Debugging Authorizations option anywhere in my settings. I do not have an explanation for why I don't, and even now after I have corrected my unauthorized issue, I still do not have it. As such, I can't speak to whether or not this particular solution will help you.</li> </ol> <h3>Here's what worked for me:</h3> Since none of the above options fixed the problem, I knew I had to dig a little deeper. The RSA keys for authorized computers are stored on the phone in <span class="code">/data/misc/adb/adb_keys</span>. Interestingly, the path existed, but I had no <span class="code">adb_keys</span> file. I don't have an explanation for why not. I also can't explain why this didn't cause the phone to prompt for authorization when connecting to the computer. To fix my problem, I had to copy the public key of my computer to my phone's <span class="code">adb_keys</span> file. <ol>  	<li>Turn off your device and disconnect it from the computer.</li>  	<li>Boot the device into Recovery Mode. [br] For me, using a Moto G5 Plus with TWRP recovery installed: <ol>  	<li>Press and hold the power and volume down buttons until the phone enters bootloader mode.</li>  	<li>Use the volume down key to step through the options until you hit Recovery.</li>  	<li>Press the power button to enter Recovery mode.</li> </ol> </li>  	<li>Open a terminal window on your PC.</li>  	<li>Find the directory on your PC where the Android keys are stored. [br] On Linux this directory is <span class="code">~/.android</span>. The public key file is named <span class="code"></span>. <pre class="terminal crayon:false"><span style="color: #00ff00;">tpodlaski@Alabama</span>:<span style="color: #00ccff;">~</span> ls -la ~/.android
total 44
drwxr-x---  5 tpodlaski tpodlaski 4096 May  9 10:31 .
drwxr-xr-x 46 tpodlaski tpodlaski 4096 May 14 11:58 ..
-rw-------  1 tpodlaski tpodlaski 1704 May  9 10:31 adbkey
-rw-r--r--  1 tpodlaski tpodlaski  719 May  9 10:31
-rw-r--r--  1 tpodlaski tpodlaski  185 Dec 19 21:21 analytics.settings
drwxr-xr-x  2 tpodlaski tpodlaski 4096 Dec 19 21:24 avd
drwxr-xr-x  2 tpodlaski tpodlaski 4096 Dec 19 19:31 cache
-rw-r--r--  1 tpodlaski tpodlaski  140 Dec 19 22:21 ddms.cfg
-rw-r--r--  1 tpodlaski tpodlaski 1258 Dec 19 21:20 debug.keystore
drwxr-xr-x  3 tpodlaski tpodlaski 4096 Dec 19 21:31 monitor-workspace
-rw-r--r--  1 tpodlaski tpodlaski   36 Dec 19 19:31 uid.txt
tpodlaski@Alabama:~</pre> </li>  	<li>Connect the phone to the PC with a USB cable.</li>  	<li>Verify the adb server sees the phone by running <span class="code">adb devices</span>. <pre class="terminal crayon:false"><span style="color: #00ff00;">tpodlaski@Alabama</span>:<span style="color: #00ccff;">~</span> adb devices
List of devices attached
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
ZY2243PNMF      recovery
  • If, unlike me, you do have an adb_keys file on your phone, copy it to your PC so that you do not overwrite it. adb pull /data/misc/adb/adb_keys ~/adb_keys
    tpodlaski@Alabama:~adb pull /data/misc/adb/adb_keys /data/misc/adb/adb_keys: 1 file pulled. 0.0 MB/s (719 bytes in 0.043s)</pre> Or if you do not have the <span class="code">adb_keys</span> file on your phone, create a blank one on your PC. <span class="code">touch ~/adb_keys</span> <pre class="terminal crayon:false"><span style="color: #00ff00;">tpodlaski@Alabama</span>:<span style="color: #00ccff;">~</span> touch ~/adb_keys
  • Append the contents of to adb_keys .  cat ~/.android/ >> ~/adb_keys
    tpodlaski@Alabama:~cat ~/.android/ >> ~/adb_keys</pre> </li>  	<li>Copy <span style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;"><span style="white-space: pre-wrap; background-color: #eff0f1;">adb_keys</span></span>  back to your phone. <span class="code">adb push ~/adb_keys /data/misc/adb/adb_keys</span> <pre class="terminal crayon:false "><span style="color: #00ff00;">tpodlaski@Alabama</span>:<span style="color: #00ccff;">~</span> adb push ~/adb_keys /data/misc/adb/adb_keys
    adb_keys: 1 file pushed. 0.3 MB/s (719 bytes in 0.003s)
  • Reboot your phone. adb reboot
  • When the phone has rebooted, rerun adb devices to verify the PC is now authorized.
    tpodlaski@Alabama:~$ adb devices 
    List of devices attached
    ZY2243PNMF      device
  • And success! Success for me anyway. Your mileage, as always, may vary. While I am pleased to be authorized again and able to continue on my way, I am still wary of the fact that I don’t know what caused this issue in the first place and why I don’t have a Revoke USB Debugging Authorizations option in my settings. If you have any insight, I kindly ask that you clue me in by leaving a comment below. Thanks!


    Skip to comment form

      • Tufan Karadere on June 12, 2017 at 10:35 am
      • Reply

      This will overwrite adb_keys file, which might contain multiple keys. An idea to save existing keys might be:

      adb pull /data/misc/adb_keys ~/adb_keys
      cat ~/.android/ >> ~/adb_keys
      adb push ~/adb_keys /data/misc/adb_keys

      1. Thank you very much for pointing this out. However I borked my phone, I had completely lost the adb_keys file, so I hadn’t even considered overwriting it. I’ve rewritten the instructions using your suggestion for people who may have an adb_keys files they need to save.

      • Giancarlo Junior on August 25, 2017 at 8:05 am
      • Reply

      Thanks, I solved the problem of my Moto G5 Plus, that there was no adb_keys file and the RSA Fingerprint window did not appear, i just followed the instructions. I also had the same problem.

      • George on September 24, 2017 at 5:55 pm
      • Reply

      I dont understand this. I tried many methods but didnt work. the last method you describe I dont understand. I’m using windows 10 pro computer

      • josemwarrior on September 25, 2017 at 7:28 am
      • Reply

      Thhhhhhaaaaaaaaaaaaaaaaaaaaaaank youuuuuuuu

        • Tony on September 25, 2017 at 10:49 am
        • Reply

        You are very welcome!

      • Mr Guinness on October 14, 2017 at 4:08 am
      • Reply

      Thanks Tony!

      I had a similar problem – my OnePlus One phone was in a boot loop previously so I booted into recovery but could not access the phone because adb was unauthorised in recovery. I had to “sneaker-net” the adb_keys file from my PC onto the phone by using a USB-otg drive.

      • Eliott on November 21, 2017 at 11:28 pm
      • Reply

      Also on a moto g5 plus (coincidence..?). Had no idea what I did but copying your instructions was good enough to fix it. Thank you so much!

      • jorge cabrero on November 25, 2017 at 8:51 pm
      • Reply

      i have a problem, i dont have a sistem, i dont have a recovery, i get a brick, please help me, is a alcatel one touch idol 3 5.5.

      • floxin on December 22, 2017 at 11:11 pm
      • Reply

      hey, I’m stealing this from mnoguti, on xdaforums:
      these are the commands listed above for windows:
      type NUL > adb_keys
      type c:\users\UserAccount\.android\ > adb_keys
      adb push adb_keys /data/misc/adb/adb_keys
      Thanks again!

    1. Many thanks, I’ve followed floxin’s tip except with the following:
      instead of NUL > adb_keys I copied and renamed it to adb_keys
      Also, copy adb_keys to the same directory as adb.exe if you using bundled tools or a version of adb not downloaded from google.
      Then adb push adb_keys /data/misc/adb/adb_keys

      • ash on September 19, 2018 at 12:37 pm
      • Reply

      Your solution is the only thing that worked for me. THANK YOU!

    2. still doesnt work for me lg g3..

      • Walter William Quinn on October 20, 2018 at 10:24 am
      • Reply

      Didn’t have any luck with any of these but I did find a way using another Android device. In my case a tablet, but I expect it will work with any device you have root access to. Plug the device into the PC you are trying to get the adb_keys for. If you authorize the connection it will generate the file you need in the /data/misc/adb folder and you can steal it from there. Copy the file to a non-root folder (Android won’t share from root floders) & email it to the phone that needs it. Download it from the email & copy it to the /data/misc/adb on the phone. Worked like a charm.

      • Maksim on October 26, 2020 at 7:16 am
      • Reply

      I’m still having the same problem. Can anyone help??
      Mine is a Nokia 2.2 with forgotten lockscreen.
      I’ve turned on the USB debugging mode earlier but now I forgot my screen-PIN, now it says device unauthorized.. how to retrieve my call lists.. somebody help, please.

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.