Skip to main content

A command-line tool for managing two-factor authentication (2FA) TOTP codes.

Project description

TFA CLI Tool

A command-line tool for managing two-factor authentication (2FA) TOTP codes.

Why did I build this?

  • I wanted to understand how TOTP codes work. I don't like trusting access to my accounts to a black box which I don't understand.
  • I don't keep my phone with me all the time.
  • I'm worried about losing access to my accounts if I lose my phone.

This project succeeded in its main goal: I now have a good understanding of how TOTP codes work.

Should you use this?

Maybe? Standard practice is to keep two-factor authentication codes on your phone, not your computer. This separation is intentional - if someone gains access to your computer, they still won't have your 2FA codes. By storing codes on your computer with this tool, you're reducing that security boundary. The security model assumes phones have better protection against unauthorised access than computers do.

The secret database is not encrypted. Secrets are stored in an sqlite database. You should keep backups, and probably use the qr code feature to add accounts to an authenticator app.

I'm also not a security expert. I'm just a programmer who wanted to understand TOTP. Maybe you should use a standard tool instead.

Use at your own risk.

Installation

uv tool install tfa

or

pip install tfa

There is no default location for the database because the point is to make secret management less opaque than typical authentication apps. You must explicitly choose where to store your secrets by setting a path in your shell configuration:

export TFA_STORAGE=~/.config/tfa/accounts.db

If TFA_STORAGE is not set, the tool will display an error message and exit.

Migrating from JSON

If you're upgrading from a previous version that used JSON storage, TFA will automatically detect this and provide migration instructions. To migrate your accounts:

tfa import ~/.config/tfa/accounts.json
export TFA_STORAGE=~/.config/tfa/accounts.db

After verifying that all your accounts were successfully migrated, you can safely remove the old JSON file.

Usage

Add a new account

tfa add <account_name> <secret_key>

# With custom issuer name
tfa add <account_name> <secret_key> --issuer "Custom Name"

# Force overwrite existing account
tfa add <account_name> <secret_key> -f

Get TOTP code

tfa code <account_name>

List accounts

tfa list

Remove account

tfa remove <account_name>

Generate QR Code

Generate a QR code to scan with other authenticator apps:

tfa qr <account_name>

Import/Export Accounts

Export accounts to JSON (useful for backups):

# Export to a file
tfa export backup.json

# Export to stdout
tfa export

Import accounts from JSON:

# Import accounts
tfa import backup.json

# Force overwrite existing accounts
tfa import backup.json --force

Examples

# Add a new GitHub account
tfa add github JBSWY3DPEHPK3PXP --issuer "GitHub"

# Get current code
tfa code github
# Output: GitHub: 123456

# List all accounts
tfa list
# Output: github

# Generate QR code
tfa qr github

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfa-0.4.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tfa-0.4.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file tfa-0.4.0.tar.gz.

File metadata

  • Download URL: tfa-0.4.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for tfa-0.4.0.tar.gz
Algorithm Hash digest
SHA256 73a07e07291b3cfb8763093df2ea8d09721638143ea1868d6046560ef6b2b209
MD5 94d9ffd5f836ef41e2393fde89f4a137
BLAKE2b-256 b6504666d3a02fac0d35bc60ec1dc1f6699cbfba9d18063fa0f9d4139c059f5c

See more details on using hashes here.

File details

Details for the file tfa-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: tfa-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for tfa-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d0f7582e7519c7862fdb25ba279e9c608745abb30cc1a057c6fda912daa0eae
MD5 727359b7f9d692d8faebfbaccf7a82f7
BLAKE2b-256 8248e7fa41c64a1087b738c7ee575e7307f976419988a7b8c91d7a4871dbeab0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page