OTP Setup Guide
This guide will help you create an OTP (One-Time Password) alias that will generate an OTP, copy it to the clipboard, and then automatically paste it in the currently active window.
Prerequisites
- oathtool: This is a command line tool for generating OTPs.
- xclip: A command line interface to X selections (clipboard).
- xdotool: This tool lets you programmatically (or manually) simulate keyboard input and mouse activity.
Install these tools on Ubuntu or any other Debian-based distribution by running the following commands:
1
sudo apt-get install oathtool xclip xdotool
Setting up the OTP Alias
To set up the OTP alias, open your bashrc file (typically located at ~/.bashrc
) with your preferred text editor. Then add the following line to the file:
1
alias otp='oathtool --base32 --totp $OTP_SECRET | xclip -sel clip; sleep 0.5; xdotool key Ctrl+v'
Replace $OTP_SECRET
with your actual secret key for generating OTPs. This can be a hard-coded string or an environment variable.
This line creates an alias otp
which:
- Generates an OTP using the oathtool.
- Copies the generated OTP to the clipboard with xclip.
- Waits for 0.5 seconds to ensure that the OTP has been copied to the clipboard.
- Simulates the paste operation by sending a Ctrl+V keystroke with xdotool.
After adding this line, save the file and close the text editor. Then, source your bashrc file by running the following command to make the new alias available:
1
source ~/.bashrc
Using the OTP Alias
To use the OTP alias, simply type otp
in the terminal and press Enter. The alias will generate an OTP, copy it to the clipboard, and then automatically paste it into the currently active window.
Note: Be careful to ensure that the correct window or text field is focused when you run this command, as it will paste the OTP into the currently active field. Also, if your terminal doesn’t support Ctrl+V for pasting (some terminals use Ctrl+Shift+V), you’ll need to adjust the xdotool
command in the alias accordingly.