Instantly share code, notes, and snippets.

What would you like to do?
Command-line Google Authenticator (TOTP)
Sample Account 1 ABCDEF0123456789
Sample Account 2 0123456789ABCDEF
#!/usr/bin/env ruby
require 'rubygems'
require 'rotp'
printf "%-30s %3s (%02ds) %4s\n", 'Account', 'Now', (30 - (Time::now.utc.to_i % 30)), 'Next'
puts '-' * 47
File::read(File.expand_path('~/.google-authenticator-accounts')).split("\n").reject{|l| l.strip == ''}.each do |account|
if account =~ /^(.+) ([\w\d]+)$/
totp =$2)
printf "%-30s %06s %06s\n", $1,, + 30)

This comment has been minimized.

Copy link

Dan-Q commented Dec 10, 2018

How to use:

Create ~/.google-authenticator-accounts containing account names and secret keys; one account per line, with a space separating the account from the (alphanumeric) key. Protect this file.

Run ./google-authenticator.rb to generate "now" and "next" TOTP codes for the entire list.

Further reading:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment