Skip to content

Instantly share code, notes, and snippets.

@theanht1
Last active April 3, 2025 02:17
Show Gist options
  • Select an option

  • Save theanht1/b155d13dc75a0ca6cb98e2ac0f5f36e8 to your computer and use it in GitHub Desktop.

Select an option

Save theanht1/b155d13dc75a0ca6cb98e2ac0f5f36e8 to your computer and use it in GitHub Desktop.
Openconnect script as a cmd client to connect to Anyconnect VPN
#!/bin/sh
VPN_URL=
VPN_GROUP=
VPN_USER=
VPN_PASSWORD=
VPN_CERT_FILE=
CERT_PASSPHRASE=
# if [ $USER != "root" ]
# then
# echo "Must be run as root."
# exit
# fi
# Prevent ctrl-c from killing the whole script
trap '' 2
# Lauch openconnect
# with user group
# echo $VPN_PASSWORD | sudo openconnect $VPN_URL --user=$VPN_USER --usergroup=$VPN_GROUP --passwd-on-stdin
# with cert file and passphrase
echo $VPN_PASSWORD | sudo openconnect $VPN_URL --user=$VPN_USER --usergroup=$VPN_GROUP --certificate=$VPN_CERT_FILE --key-password=$CERT_PASSPHRASE --passwd-on-stdin
# Stop trapping ctrl-c
trap 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment