Skip to content

Instantly share code, notes, and snippets.

@nicoelayda
Last active February 28, 2022 12:25
Show Gist options
  • Select an option

  • Save nicoelayda/003585d1340b1ff4adae0b2e723fb8e3 to your computer and use it in GitHub Desktop.

Select an option

Save nicoelayda/003585d1340b1ff4adae0b2e723fb8e3 to your computer and use it in GitHub Desktop.
These steps are for running Cisco AnyConnect in headless mode (no GUI and icon in the dock) and automatically providing VPN credentials using a response file.

Cisco AnyConnect Headless Operation and Auto Login on macOS

These steps are for running Cisco AnyConnect in headless mode (no GUI and icon in the dock) and automatically providing VPN credentials using a response file.

Tested on

  • macOS Monterey 12.2.1
  • Cisco AnyConnect Secure Mobility Client 4.9.05042

Setup

  1. Create a symbolic link to /opt/cisco/anyconnect/bin/vpn in /usr/local/bin/anyconnect

    ln -s /opt/cisco/anyconnect/bin/vpn /usr/local/bin/anyconnect
  2. Create a response file in ~/.config/anyconnect/response.txt containing your username and password.

    mkdir -p ~/.config/anyconnect
    tee -a ~/.config/anyconnect/response.txt > /dev/null <<"EOF"
    <YOUR-USERNAME-HERE>
    <YOUR-PASSWORD-HERE>
    
    EOF

    Note: The empty line after the password is important. See the sample-response.txt included with this gist.

Commands

Connect to VPN

Run anyconnect connect, passing your VPN server URL and path to response file.

anyconnect connect vpn.example.com -s < ~/.config/anyconnect/response.txt

Tip: You can add an alias to your shell configuration to make it even easier to connect, for example:

  1. Add this to .zshrc (for zsh users) or .bash_profile (for bash users):

    alias connect_vpn="anyconnect connect vpn.example.com -s < ~/.config/anyconnect/response.txt"
    
  2. Restart your terminal.

  3. Now, to connect to your VPN, you can simply type

    connect_vpn
    

Disconnect from VPN

anyconnect disconnect

Check connection state

anyconnect state
nicoelayda
p@ssw0rd123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment