Skip to content

Instantly share code, notes, and snippets.

@dptole
Created April 29, 2023 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dptole/4197a9f0e1f1249058955d8cd23c0a6f to your computer and use it in GitHub Desktop.
Save dptole/4197a9f0e1f1249058955d8cd23c0a6f to your computer and use it in GitHub Desktop.
Import OpenVPN files en mass using nmcli (Network Manager CLI)
#!/usr/bin/bash
# You must be in the folder containing all *.ovpn files
username="USERNAME FOR ALL CONNECTIONS"
password="PASSWORD FOR ALL CONNECTIONS"
for path in `ls *.ovpn`
do
connectionName=$(basename $path ".ovpn")
nmcli --terse connection delete id "$connectionName"
nmcli --terse connection import type openvpn file "$path"
nmcli connection modify "$connectionName" vpn.persistent true
nmcli connection modify "$connectionName" vpn.user-name "$username"
nmcli connection modify "$connectionName" +vpn.data "password-flags = 0, username = $username"
nmcli connection modify "$connectionName" +vpn.secrets "password=$password"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment