Starting Cisco AnyConnect from Terminal

DISCLAIMER: This isn't a solution to connecting if you don't already have Cisco AnyConnect installed. I've been there and if you're a contractor not using Windows and your customer doesn't have a copy of Cisco AnyConnect for Mac to give you it will be difficult to find or trust that it's a legit copy. Why Cisco won't just give access to downloads on their site without a vendor login is a mystery to me. You can get it on the iOS App Store without a problem.

The Path:

If you want to manage your Cisco AnyConnect VPN from the Terminal on Mac you can do this...

You can enter the vpn shell from this path.


Cisco AnyConnect CLI Mac Terminal Screenshot

Once started you can use the connect command.

Cisco AnyConnect CLI Mac Terminal Connect to Host Screenshot

VPN> connect # or whatever host you're trying to connect to.  

Or One Liners:

/opt/cisco/anyconnect/bin/vpn connect 

/opt/cisco/anyconnect/bin/vpn state

/opt/cisco/anyconnect/bin/vpn disconnect 

Make an Alias:

If you're familiar with dot files then this is simple, if not then just follow along.

Open a new terminal shell. On my Mac I have a /Users/trozdol/.aliases file I'll be using and my alias will be called anyconnect.

If you don't have any custom dotfiles in place run ls -la in your $HOME dir. This lists all files and folders including hidden dotfiles.

If you see a .bashrc or .bash_profile just use either of those. If you do not create the file .bash_profile This is automatically loaded in the terminal when a shell is opened.

Add a new alias like below. Mine is anyconnect, but you can call it anything you'd like that doesn't already exist.

vim .bash_profile # if you don't have it this will create the file on save.  

Once in the VIM editor hit the i key to switch to INSERT (edit) mode and type...

alias anyconnect="/opt/cisco/anyconnect/bin/vpn"  

Once done use these commands to save and exit - ESC then type :wq for write and quit.

Now you can test this by opening a new Terminal shell and typing your alias. If you see the AnyConnect shell your good to go.

anyconnect [connect | state | disconnect]

anyconnect help # to see some other commands available.