Cisco on macOS / Linux
Don't launch the GUI client. Everything here drives the command-line interface so the login can be scripted.
On a standard desktop install, the CLI lives at:
/opt/cisco/secureclient/bin/vpnmacOS users can alternatively install the iOS-style AnyConnect client, which also supports split tunneling, but features and stability vary by version.
Prerequisites
# Debian/Ubuntu
sudo apt install oathtool
# macOS
brew install oath-toolkitYou also need Cisco AnyConnect / Secure Client already installed, so that /opt/cisco/secureclient/bin/vpn exists.
Quick install
curl -fsSL https://sh.mawenqian.com/cisco-unix-install.sh | bashWhat it does:
- Drops
cisco-vpn.shand aconfig.shtemplate into/opt/cisco-vpn. Override withINSTALL_DIR=.... Creating the directory needssudo, same as the OpenConnect installers. - Makes
cisco-vpn.shexecutable and symlinks it to~/.local/bin/ciscovpn. - If
~/.local/binisn't on yourPATHyet, appends anexport PATH=...line to.bashrc/.zshrc/.profile(whichever matches$SHELL), sociscovpnactually works after you restart your shell. It checks for that exact line first, so re-running never duplicates it.
Re-running it later refreshes cisco-vpn.sh without touching your config.sh, so it doubles as an update mechanism.
Manual install
- Copy
Cisco/unix/cisco-vpn.shandCisco/unix/config.shwherever you like. - Edit
config.shwith your realVPN_HOST,VPN_USER,VPN_PASSWORDandVPN_SECRET. - Make the script executable:
chmod +x cisco-vpn.sh
Usage
ciscovpn connect # disconnect any existing session, then log in
ciscovpn disconnect # disconnect
# or, if you installed manually / skipped the symlink:
./cisco-vpn.sh connect
./cisco-vpn.sh disconnectUnder the hood
cisco-vpn.sh generates a fresh TOTP code with oathtool and pipes a scripted command sequence into the CLI's -s (stdin-scripted) mode. The CLI doesn't accept connect <host> as a plain command-line argument on either platform; it only reacts to that sequence typed at its own interactive VPN> prompt. The Windows side uses the same mechanism via vpncli.exe -s.
printf 'connect %s\n%s\n%s\n%s\n' "$VPN_HOST" "$VPN_USER" "$VPN_PASSWORD" "$OTP" \
| /opt/cisco/secureclient/bin/vpn -sNothing touches disk. The credentials only exist in the pipe between this script and the CLI process for the moment it takes to read them.