Skip to content

Instantly share code, notes, and snippets.

@djleonskennedy
Last active April 15, 2021 09:28
Show Gist options
  • Save djleonskennedy/aa4a53265523d2bd805bb5cea7e40f48 to your computer and use it in GitHub Desktop.
Save djleonskennedy/aa4a53265523d2bd805bb5cea7e40f48 to your computer and use it in GitHub Desktop.
connect to vpn via "openconnect" automatically with OTP
#!/bin/sh
PASSWORD=<userpassword>
BASE32_TOKEN=<BASE32 SECRET>
HOST=vpn.some.com
# topt token generation
# tools can be get here https://www.nongnu.org/oath-toolkit/
# also don't forget to set current time
# this method is using is in case if "token" and "password" swapped
# with default topt config use this http://www.infradead.org/openconnect/token.html (no oathtool required)
TOKEN=`oathtool --base32 --totp $BASE32_TOKEN`
#user input sequence
sequence="${TOKEN}\n${PASSWORD}"
# CONFIG example
<< ////
user=<username>
authgroup=<group name>
passtos
os=win
////
printf $sequence | openconnect --script /etc/vpnc/vpnc-script --config=CONFIG $HOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment