At work we use Pritunl to connect to the office VPN. This process involves entering a password and a two factor authentication token.
Tired of manually connecting using the graphical user interface and pulling my phone to get a new 2FA every time, I went ahead and tried to automate the process.
It turns out that, in Linux, Pritunl offers two clients: CLI and GTK. Using the CLI one, once you have imported the VPN profile, you can connect to a VPN like this:
# get the connection ID using: pritunl-client list # connect to the VPN using: pritunl-client start CONNECTION_ID --password YOUR_PASSWORD
The above works if no 2FA is required, which is not my case. To automate getting one, I used rsc/2fa. Once you configure it you can do something like this:
OTP=$(2fa vpn) pritunl-client start CONNECTION_ID --password YOUR_PASSWORD$OTP
i.e., you need to append the 2FA to the password.