Skip to content

Instantly share code, notes, and snippets.

@zypA13510
Last active April 16, 2025 03:23
Show Gist options
  • Save zypA13510/05e3c1349d450351451e162e2b94eabb to your computer and use it in GitHub Desktop.
Save zypA13510/05e3c1349d450351451e162e2b94eabb to your computer and use it in GitHub Desktop.
Systemd unit file for OpenConnect VPN client

Config file

  • Name config file like mycompany.conf and put it under /etc/openconnect/.
  • If password authentication is required, put password in mycompany.passwd in the same folder.
  • You can have multiple sets of config file if required.

Systemd unit

  1. Download [email protected] to /etc/systemd/system/
  2. systemctl daemon-reload
  3. systemctl start openconnect@mycompany (needs to match the name of config file)
  4. Check status with: systemctl status openconnect@mycompany
  5. If everything works, set the service to auto-start on boot: systemctl enable openconnect@mycompany
[Unit]
Description=OpenConnect VPN Client on %I
After=network.target
[Service]
Type=forking
RuntimeDirectory=openconnect
PIDFile=/run/openconnect/%i.pid
WorkingDirectory=/etc/openconnect
ExecStart=/usr/sbin/openconnect --non-inter --passwd-on-stdin --background --pid-file /run/openconnect/%i.pid --config %i.conf
StandardInput=file:/etc/openconnect/%i.passwd
Restart=on-failure
RestartSteps=30
RestartMaxDelaySec=3600
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment