Skip to content

One-time password (OTP) implementation in Shell, Python and Go



One-time password (OTP) is a security mechanism that generates a unique password for each login attempt. It adds an extra layer of security to user accounts as the passwords expire immediately after use. OTP implementation can be done in different programming languages, including Shell, Python, and Go. In this article, we will discuss how OTP can be implemented in these languages.

OTP Implementation in Python

install pyotp

pip install pyotp

demo python code

import pyotp
totp = pyotp.TOTP('XXXXXXXX')

OTP Implementation in Go

install go-otp

go get

demo go code

package main

import (

func main() {
    fmt.Println("Current OTP is", gotp.NewDefaultTOTP("XXXXXXXX").Now())

OTP Implementation in Shell

install oathtool

## Debian & Ubuntu
apt install oathtool

## CentOS & Fedora
sudo yum -y install oathtool
sudo dnf -y install oathtool

## Mac 
brew install oath-toolkit

demo command

oathtool -b --totp XXXXXXXXX


OTP is a simple and effective security mechanism that can be implemented in different programming languages. In this article, we discussed how OTP can be implemented in Shell, Python, and Go. While the implementation may vary, the basic principle remains the same: generating a unique password that expires immediately after use.


Leave a message

  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • Made with Material for MkDocs and improve writing by generative AI tools
  • Copyright issue feedback, replace # with @