$> man42.net Blog written by a human

This is a guide to backup / extract / transfer Google Authenticator QR codes from one rooted Android device to any non-rooted device.

# Prerequisites

  • The original Android device must be rooted.
  • You'll need Python and adb to be installed.

# Steps

  • Enable developer options on your Android device where Google Authenticator is installed.

  • In the developer options, enable Android debugging (ADB) and enable Root access: for ADB

Then on your computer:

  • Open a terminal.

  • Run mkdir authenticator-backup (Create a folder to store the data)

  • Run cd authenticator-backup (Move to this folder)

  • Run adb root (to gain root access on the Android device -- you might have to accept the prompt on your Android device)

  • Run adb pull /data/data/com.google.android.apps.authenticator2/databases/databases (to grab your Google Authenticator database containing your secrets)

  • Tips: If you have sqlite3 installed, you can list your secrets with this command: sqlite3 ./databases "select * from accounts" (you can then add them manually on Google Authenticator if you want to, without needing the python script below)

  • Extract QR codes - Create a generate-qrcodes.py file with the following content (thanks Zian for the script):

import qrcode
import sqlite3
conn = sqlite3.connect('./databases')
c = conn.cursor()

for idx, (email, secret, issuer) in enumerate(c.execute("SELECT email,secret,issuer FROM accounts").fetchall()):
   if issuer==None:
       if len(email.split(" "))>0:
           issuer=email.split(" ")[0]
       else:
           issuer=email

       if len(issuer.split(":"))>0:
           issuer=issuer.split(":")[0]

       print("If the following issuer looks wrong, enter a new value. If it's OK, just press ENTER.")
       newIssuer=input(issuer)
       if len(newIssuer)>0:
           issuer=newIssuer
   url = 'otpauth://totp/{}?secret={}&issuer={}'.format(email, secret, issuer)
   print (url)
   im = qrcode.make(url)
   im.save('./{}.png'.format(idx))
  • Run pip install sqlite3 qrcode Image (Install required Python dependencies)

  • Run the script python ./generate-qrcodes.py and follow the instructions.

You can now find all the X.png pictures containing your QR codes backup!

Remember to safely remove the ./databases file and the QR codes images after backuping them in a secure place.

# Restoring your Google Authenticator QR codes

If you want to restore your QR codes to a new device, you now just have to scan your backed up QR codes from the app :)

Buffer this pageShare on TumblrDigg thisShare on FacebookShare on LinkedInTweet about this on TwitterEmail this to someoneShare on Google+Share on RedditPin on Pinterest