Last active
June 22, 2016 18:48
-
-
Save jnerin/4eb3992505a924193a61 to your computer and use it in GitHub Desktop.
.ovpn file generator
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
#!/bin/bash | |
# | |
# Copyright (c) 2014 Jorge Nerín <[email protected]> | |
# Last updated on: Jun/26/2014 by Jorge Nerín | |
# | |
############################################################################ | |
# | |
# .ovpn file generator (OpenVPN configuration files) | |
# | |
# It expects to find files with this names: | |
# * ca.crt | |
# * dh2048.pem | |
# * tls-auth-static-key.key | |
# * $1.{crt,key} | |
# | |
# Run it "generate-ovpn.sh username" and it'll look for files | |
# username.crt, username.key and the server files (ca.crt, dh2048.pem, | |
# tls-auth-static-key.key). It'll generate a username.ovpn with | |
# everything included and ready to use. | |
# | |
# Edit as needed. At least the SERVER variable, it'll make your life | |
# easier. | |
# | |
############################################################################ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################ | |
SERVER=your.openvpn.connection.point | |
# Redirect STDOUT to the file | |
exec >${1}.ovpn | |
cat <<EOF | |
client | |
verb 4 | |
connect-retry-max 5 | |
connect-retry 5 | |
resolv-retry 60 | |
comp-lzo | |
dev tun | |
remote ${SERVER} 1194 udp | |
remote-cert-tls server | |
<ca> | |
EOF | |
cat ca.crt | |
cat <<EOF | |
</ca> | |
<key> | |
EOF | |
cat ${1}.key | |
cat <<EOF | |
</key> | |
<cert> | |
EOF | |
# cat ${1}.crt # Naïve, includes extra headers from crt that are | |
# troublesome for some clients when importing the file | |
# Solution from: http://unix.stackexchange.com/a/56432 | |
sed -n '/^-----BEGIN CERTIFICATE-----$/ { p; s///; :a; n; p; ba; }' ${1}.crt | |
cat <<EOF | |
</cert> | |
<tls-auth> | |
EOF | |
cat tls-auth-static-key.key | |
cat <<EOF | |
</tls-auth> | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment