Automatic Google Auth VPN Connection Script
If you're using a Mac (although this may work on Linux too), and have OpenVPN setup for yourself which requires Two Factor Authentication using Google Authenticator, then you can use this to automate your connection.
Warning : This script requires sudo access
- homebrew : If you've never used
brewin your terminal, please check here on how to install homebrew.
- Python and pip : If you don't have python/pip, I'd really suggest not to use the script at all.
Instructions to install
- Install oath-toolkit :
brew install oath-toolkit
- Install pexpect for python :
pip install pexpect
- Install OpenVpn CLI :
brew install openvpn
- Add the following into
export PATH=$(brew --prefix openvpn)/sbin:$PATH
Clone/Download the repo :
git clone https://github.com/bhavul/automated-google-auth-vpn.git
Find your Google Auth VPN Secret Key. It shall be somewhat like this :
NOTE : If you don't have this saved, you will need to contact the people who had set it up for you - the IT Team, or whoever. The first time you set it up, or scan QR Code, it is visible at that time.
Open the cloned repository, and open the
config.propertiesfile in a text editor. Edit and fill each field to your own. Once done, save the file.
You're all done.
How to use?
- Open terminal.
cdinto cloned repository
connect-vpn.pyusing python 3 :
Note that this will occupy one of your terminal and push all the logs in there itself. If you wish to keep this all in background, I suggest to use tmux / screen and launch this there.
You can also push all logs to a file like so :
python3 connect-vpn.py > vpn.log 2>&1
What's the point of this?
Frankly, this takes away the security that Two factor auth provides. So, I'm not responsible for anything that may happen if you use this script. I just wrote it for automating my workflow.