TOTP (Time-based One-Time Password) is a popular method for two-factor authentication (2FA). It generates a time-based code that adds extra security when logging into websites or applications. The totp-cli
is a simple command-line tool that helps you manage TOTP tokens on your Ubuntu machine.
This guide is perfect for beginners who want to install, configure, and use totp-cli
to secure their accounts. We will walk you through the process of installing totp-cli
, adding and managing TOTP secrets, and even how to back up and restore your TOTP tokens. By the end of this article, you’ll have a good understanding of how to use this tool to enhance your security.
Step 1: Install Go (Required for totp-cli
)
totp-cli
is written in Go, so you need to have Go installed on your system before you can install totp-cli
. Follow these steps:
- Update your system: Open a terminal and run:
sudo apt update
- Install Go: Install Go by typing:
sudo apt install golang-go
Go is now installed and ready for use.
Step 2: Install totp-cli
Now, let’s install totp-cli
using Go:
- Install
totp-cli
: Run this command to installtotp-cli
:go install github.com/agrinman/totp-cli@latest
- Set the Go path (if needed): If Go isn’t in your system’s path, you need to add it. Add this to your
.bashrc
file:export PATH=$PATH:$HOME/go/bin
- Reload your terminal: Run this command to refresh your terminal:
source ~/.bashrc
Now, you can run totp-cli
from anywhere on your system.
Step 3: Configure totp-cli
Once installed, you can start adding your TOTP secrets (codes for 2FA). You will need to manually add secrets that you get from your accounts.
- Add a TOTP secret: To add a new TOTP secret, use this command:
totp-cli add "My Account" YOUR_SECRET
Replace
"My Account"
with the name of your account andYOUR_SECRET
with the actual TOTP secret code you got from the app or website you want to secure. - List your TOTP accounts: You can see all your TOTP accounts using this command:
totp-cli list
- Generate a TOTP code: To generate a TOTP code, just run:
totp-cli generate "My Account"
This will generate a time-based code that you can use for logging in.
Step 4: Backup Your TOTP Secrets
It’s important to back up your TOTP secrets so you don’t lose access to your accounts if something happens to your computer.
- Create a backup: You can back up all your TOTP secrets by running:
totp-cli dump > backup.json
This saves all your secrets to a file called
backup.json
. Make sure to store this file in a secure place.
Step 5: Restore TOTP Secrets
If you ever need to restore your TOTP secrets (for example, on a new machine), follow these steps:
- Import the backup: Use this command to restore the secrets from your backup file:
totp-cli import < backup.json
This will restore all your previously saved TOTP secrets from the
backup.json
file.
Conclusion
With totp-cli
, you can easily manage TOTP codes from the command line on your Ubuntu system. This guide showed you how to install Go and totp-cli
, configure it with your TOTP secrets, and perform useful tasks like generating codes, backing up, and restoring your secrets. Regular backups are very important to keep your accounts safe, so don’t forget to save your TOTP secrets securely. By following these steps, you’ll be able to improve your account security in a simple and effective way.