Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
auto login with cisco anyconnect (password saved, silent mode)

Cisco AnyConnect: auto login in silent mode

This gist is for Linux. For windows is the same thing.

Connect

create a file .login_info as below:

connect your.server.url    
usernanme  
password
    (blank line)  

create a script as below

/opt/cisco/anyconnect/bin/vpn -s < .login_info   

Trouble shooting

The input (content of .login_info) may vary according to your settings. Try VPN shell to determine your inputs.

Run
/opt/cisco/anyconnect/bin/vpn -s

Now you are in command shell:
VPN>

Connect your server:
VPN> connect your.vpn.server

Input what asked, for me it's below:
Username: [xxxxx] xxxxx
Password: xxxxxx

Exit from VPN shell:
VPN> exit (or return)

Remember what you typed, and save them into the .login_info file.

Disconnect

With this approach, the icon will not show in the taskbar, you need run command line vpn disconnect to disconnect.
If you want to show the icon in the taskbar, add below line in the script:

/opt/cisco/anyconnect/bin/vpnui &
@Blastocerus
Copy link

Blastocerus commented Jun 24, 2020

Thank you so much for sharing this. I would never have been able to figure this out myself!

@dbaldon
Copy link

dbaldon commented Sep 3, 2020

I have been trying to automate logging on to the AnyConnect VPN for ages but could never find the answer. Thanks so much for sharing this. BTW, on my Windows 10 box, the file name is vpncli not vpn.

Now to modify it to watch for timeouts and automatically logon again.

@i0na-k
Copy link

i0na-k commented Sep 9, 2020

I think the program isn't entering my password. Even if I don't include username, it's still picking it up when I run the/opt/cisco/anyconnect/bin/vpn -s script. Anyone else have an issue with supplying the password? I am getting a login failed when running the script, however I can log in manually with the VPN CLI.

@dbaldon
Copy link

dbaldon commented Sep 24, 2020

My username is automatically entered as well so I don't provide it in the input file. Instead, I place the group number on the second line.

@abdashaffan
Copy link

abdashaffan commented Oct 6, 2020

for anyone that cant input the password from the .login_info file, use newline (\n) at next line after your VPN password

example:
connect <your_vpn_url>
<your_vpn_group_name> (optional, depending on your vpn type)
<your_vpn_username>
<your_vpn_password>
\n --> ADD THIS

works on MAC OS 10.15.5

@Arazsx
Copy link

Arazsx commented Jul 25, 2021

is there anyway to pass connect anyway for untrusted servers certifications?

@vatdnv
Copy link

vatdnv commented Dec 31, 2021

This is awesome. Thank you 😀

@JustinFeistner
Copy link

JustinFeistner commented Jan 7, 2022

FYI - If you have the cisco anyconnect UI open at the while you're toying with this, you'll see a message looking like:

"Connect not available. Another AnyConnect application is running or this functionality was not requested by this application."

Don't forget to close the UI completely.

@b4d
Copy link

b4d commented Jan 11, 2022

Any workaround for this:

    - Certificate does not match the server name.
    - Certificate is from an untrusted source.
Connecting to this server may result in a severe security compromise!

Most users do not connect to untrusted servers unless the reason for the error condition is known.

Connect Anyway? [y/n]: y

@ha10id
Copy link

ha10id commented Mar 9, 2022

Any workaround for this:

    - Certificate does not match the server name.
    - Certificate is from an untrusted source.
Connecting to this server may result in a severe security compromise!

Most users do not connect to untrusted servers unless the reason for the error condition is known.

Connect Anyway? [y/n]: y

connect <your_vpn_url>
y
<your_vpn_group_name> (optional, depending on your vpn type)
<your_vpn_username>
<your_vpn_password>

@lsloan
Copy link

lsloan commented May 13, 2022

This was really helpful and works well on macOS.

I'd noticed the -s option on my own, because of this helpful message from the CLI:

$ /opt/cisco/anyconnect/bin/vpn -h

    Usage: vpn [options] | [cmd] [host]

       options:
            -h         Print this usage statement.
            -v         Print version.
            -s         Read commands from response file to work non-interactively.
                       Example: vpn -s < response.txt

       commands: [connect|disconnect|hosts|state|stats]

But I wasn't getting the contents of response.txt (as they call it) correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment