Last active
September 25, 2024 18:41
-
-
Save bsless/90667a5dd8e3bc5218bef2dc12fe7905 to your computer and use it in GitHub Desktop.
Set up a bunch of OpenVPN connections using nmcli with username and password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
USERNAME="$1" | |
PASS="$2" | |
for f in *.ovpn | |
do | |
name=`basename -s .ovpn $f`; | |
nmcli connection import type openvpn file $f | |
nmcli connection modify "${name}" +vpn.data connection-type=password-tls | |
nmcli connection modify "${name}" +vpn.data username="${USERNAME}" | |
nmcli connection modify "${name}" +vpn.secrets password="${PASS}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script could be simplified and improved a bit. One could also add a thrird argument to provide a path where the processed OVPN files should be located. I usually also append the following configuration to
nmcli c mod
:ipv6.method disabled
(I have no IPv6 in my local and remote networks);ipv4.never-default yes
(I usually want to connect to specific servers only via the VPN; some VPN servers require it to be set tono
though).Changes:
;
at a command;$()
;${name}
,${USERNAME}
and${PASS}
, as the curly brackets are unnecessary;f
variable in order to make that filenames that contain spaces and special characters don’t cause any issues;nmcli connection modify
commands;name
variable, as it would be used only once;+
beforevpn.secrets
, as AFAIk there is only one secret (password
);nmcli connection import
tonmcli c i
;nmcli connection modify
tonmcli c mod
;do
to the previous line (this change is not necessary, it is only a style preference).