Skip to content

Instantly share code, notes, and snippets.

@oxagast
Forked from renatolfc/ovpn-writer.sh
Last active July 10, 2023 03:39
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 oxagast/600e13b35bc1890a402e0a8bcaf303d3 to your computer and use it in GitHub Desktop.
Save oxagast/600e13b35bc1890a402e0a8bcaf303d3 to your computer and use it in GitHub Desktop.
Script to generate an OpenVPN client configuration file in the unified format
#!/bin/sh
##
## Usage: ./ovpn-writer.sh SERVER CA_CERT CLIENT_CERT CLIENT_KEY > client.ovpn
##
server=${1?"The server address is required"}
cacert=${2?"The path to the ca certificate file is required"}
client_cert=${3?"The path to the client certificate file is required"}
client_key=${4?"The path to the client private key file is required"}
#tls_key=${5?"The path to the TLS shared secret file is required"}
cat << EOF
client
dev tun0
remote ${server}
user nobody
group adm
resolv-retry infinite
nobind
persist-key
persist-tun
verb 1
keepalive 5 120
port 1194
proto udp
remote-cert-tls server
log-append /var/log/openvpn/openvpn.log
cipher AES-128-GCM
#script-security 2
#route-noexec
#route-up /bin/false
pull
reneg-sec 3600
<ca>
EOF
cat ${cacert}
cat << EOF
</ca>
<cert>
EOF
cat ${client_cert}
cat << EOF
</cert>
<key>
EOF
cat ${client_key}
cat << EOF
</key>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment