How to: backup google authenticator app two-factor secrets
Quick and dirty:
- Connect your device to the PC via USB
- Enable debugging mode
- From the terminal:
adb root
adb pull /data/data/com.google.android.apps.authenticator2/databases/databases
sqlite3 ./databases "select * from accounts" > ./gauth_backup.txt
If you want to generate an auth code from a TOTP secret you can use oathtool
:
oathtool --base32 --totp "<secret>"
Enjoy!
Pro tip: to generate all the QR codes from the sqlite
database you could use this python script (which requires the qrcode
module):
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()):
url = 'otpauth://totp/{}?secret={}&issuer={}'.format(email, secret, issuer)
print url
im = qrcode.make(url)
im.save('{}.png'.format(idx))
(source: thouis)