Time based One Time Password authentication Wikipedia has become more commonly used in Multi-Factor Authentication (MFA) for additional security in various areas. Generally used by authenticators such as FreeOTP, Microsoft Authenticator, Google Authenticator and many more. My preference is FreeOTP due to the ability to back up the configuration without having to use a proprietary system.
OPNSense has supported TOTP for several years, and we will discuss how to set it up. I will be using OPNSense v25.01.12, and offering a script we wrote to deploy the QR Codes most authenticators prefer.
We are mainly focused on using MFA, using TOTP with an authentication for Road Warrior VPN access.
Assuming all is good, you have set up authentication. Now, you need to implement it.
Attempt to log in from a second session. If it all works, you are now authenticating with and without TOTP. Try logging in with just the password, and with the TOTP Authenticator token preceding the password (######password)
The QR Code is sensitive information. Anyone with access to the OTP Seed can use any Authenticator app to calculate the correct TOTP code. Treat this as the same level of sensitivity as you would passwords.
Ensure all of your users have their TOTP Authenticator working. There is no simple way I have found to get the QR Code to everyone. For just a few people, you can simply go to System | Access | Users, right click on their QR Code and put it where they can scan it into their Authenticator app.
For larger numbers of end users, I wrote a pair of scripts that will scan an OPNSense configuration file and create the QR Codes for each user. The user accesses the web page, enters their OPNSense username and password, and the QR Code is displayed for them.
Be aware of the security concerns if you use this script. Read the README.md file. The scripts can be downloaded via Subversion at
svn co http://svn.dailydata.net/svn/web_pages/trunk/totp_opnsense
The README.md file contains full instructions on usage.
Warning: Once this step is done, you will not be able to access VPN or the WebUI without TOTP Authentication. You will, however, be able to ssh into the router and recover the previous configuration file.
To deploy, simply remove (uncheck) Local Database for the Authentication Server.
Some VPN clients have configurations for TOTP, but each is different. All it does is prepend the TOTP code you enter to the password, so if your client does not have a separate field, you can simply prepend the six digit TOTP to your normal password. Once I have tested more, I may update this document for various OpenVPN clients.