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

This comment has been minimized.

Copy link

@Blastocerus Blastocerus commented Jun 24, 2020

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

@dbaldon

This comment has been minimized.

Copy link

@dbaldon 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

This comment has been minimized.

Copy link

@i0na-k 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

This comment has been minimized.

Copy link

@dbaldon 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

This comment has been minimized.

Copy link

@abdashaffan 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

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