Skip to content

Instantly share code, notes, and snippets.

@InFog
Last active August 7, 2025 13:38
Show Gist options
  • Save InFog/f73f974d42d59882733fd5f44469933d to your computer and use it in GitHub Desktop.
Save InFog/f73f974d42d59882733fd5f44469933d to your computer and use it in GitHub Desktop.
OpenVPN management
# Remember to first import the config into openvpn3. Change the $CONFIG_NAME into name that makes sense to you
# openvpn3 config-import --config profile.ovpn --name $CONFIG_NAME
# Add the code below to your shell's .rc file. Replace the strings below with the proper values.
# - $CONFIG_NAME
# - EMAIL_ADDRESS
# - BASE64_ENCODED_PASSWORD - To avoid exposing your password
vpn-off () {
openvpn3 session-manage --config $CONFIG_NAME --disconnect 2> /dev/null
printf "Disconnected from VPN.\n"
}
vpn-on () {
if [ -z "$1" ];
then
echo "Usage: vpn-on <2FA code>\n";
else
vpn-off
printf "Connecting to VPN.\n"
printf "EMAIL_ADDRESS\n$(echo "BASE64_ENCODED_PASSWORD==" | base64 --decode)\n$1" | openvpn3 session-start --config $CONFIG_NAME
printf "Connected to VPN.\n"
fi
}
vpn-status () {
if [ -z "$(openvpn3 sessions-list | grep "Client connected")" ]; then
printf "VPN is disconnected.\n";
else
printf "VPN is connected.\n";
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment