Skip to content

Instantly share code, notes, and snippets.

@chaddupuis
Last active November 30, 2023 23:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chaddupuis/db282205c979b21385338a0525cc2886 to your computer and use it in GitHub Desktop.
macOS Cisco AnyConnect CLI Connect Without Password (using macOS keychain)
#!/bin/sh
VPNNUM=#you might not have a choice here, so possibly not needed
ADDRESS=vpn.com
USER=yourusername
PASS=$(security find-generic-password -a yourusername -l yourkeylistitem -w)
/usr/bin/expect -f - <<EOD
set timeout 20
spawn /opt/cisco/anyconnect/bin/vpn connect $ADDR
expect "\r\nGroup:*" {send -- "$VPNNUM\r"} ##may not need
expect "\r\nUsername:*" {send -- "$USER\r"}
expect "\r\nPassword: " {send -- "$PASS\r"}
expect "Connected"
EOD
# /opt/cisco/anyconnect/bin/vpn disconnect to disconnect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment