Benutzer-Werkzeuge

Webseiten-Werkzeuge


wiki:linux:openvpn

Inhaltsverzeichnis

OpenVPN

Mit OpenVPN von Überall ins eigene/heimische Netz. Hier a Beispiel mit FLi4L als Router.

Quellen:

Server

Zertifikate und Schlüssel für den Server erzeugen:
Vorbereitung:

sudo apt-get install easy-rsa

Arbeitsverzeichnis für die Erstellung der Schlüssel und Zertifikate erstellen:

make-cadir My_Certificate_Authority && cd My_Certificate_Authority

Parameter des Zertifikatsausstellers bearbeiten:

mcedit vars
...
set_var EASYRSA_REQ_COUNTRY	"DE"
set_var EASYRSA_REQ_PROVINCE	"NIEDERSACHSEN"
set_var EASYRSA_REQ_CITY	"Hildesheim"
set_var EASYRSA_REQ_ORG	"Familie von Thuelen"
set_var EASYRSA_REQ_EMAIL	"Christoph@von-Thuelen.de"
set_var EASYRSA_REQ_OU		"Familie"
...
#EOF

PKI Initialisieren (Unterverzeichnisse werden erstellt):

./easyrsa init-pki

„.rnd“-File generieren:

openssl rand -writerand ./pki/.rnd

CA Zertifikat erstellen:

./easyrsa build-ca nopass
# ohne "nopass" --> Password: ZFxhJYWCGj2QUhMQ
# mit "nopass" --> keine weitere Passwortabfrage
# ... Common Name (eg: your user, host, or server name) [Easy-RSA CA]: <empty>
# --> pki/private/ca.key
# --> pki/ca.crt wird  generiert

Server Schlüssel erstellen:

./easyrsa gen-req dsl-router nopass
# --> pki/reqs/dsl-router.req
# --> pki/private/dsl-router.key

Server Zertifikat erstellen:

./easyrsa sign-req server dsl-router
# --> pki/issued/dsl-router.crt

Diffie-Hellman Parameter erstellen:

./easyrsa gen-dh
# --> pki/dh.pem
cp pki/dh.pem /pki/dh2048.pem

TSL-Auth Schlüssel erstellen:

openvpn --genkey --secret tsl-auth.key
# --> tsl-auth.key

Client

Zertifikate und Schlüssel für den Client erzeugen:

make-cadir OpenVPN_Clients && cd OpenVPN_Clients

Client Schlüssel erstellen:

./easyrsa gen-req Christophs_Smartphone nopass
# --> pki/reqs/Christophs_Smartphone.req
# --> pki/private/Christophs_Smartphone.key

Client Zertifikat erstellen:

./easyrsa sign-req client Christophs_Smartphone
# --> pki/issued/Christophs_Smartphone.crt

OpenVPN Client Konfigurationsdatei „*.ovpn“ erstellen:

mkdir ../Christophs_Smartphone
cp pki/ca.crt ../Christophs_Smartphone/
cp pki/issued/Christophs_Smartphone.crt ../Christophs_Smartphone/
cp pki/private/Christophs_Smartphone.key ../Christophs_Smartphone/
cp ../template_client_config.ovpn ../Christophs_Smartphone/Christophs_Smartphone.ovpn
cp tsl-auth.key ../Christophs_Smartphone/
cd ..
./make_openvpn_client_config.sh Christophs_Smartphone
template_client_config.ovpn
client
dev tun
proto udp
remote <FQDN if OpenVPN-Server> <port>
resolv-retry infinite
nobind
persist-key
persist-tun
key-direction 1
remote-cert-tls server
cipher AES-256-CBC
data-ciphers AES-256-CBC
verb 3
make_openvpn_client_config.sh
#!/bin/bash
 
# First argument: Client identifier
CONFIG_NAME=$1
BASE_CONFIG=template_client_config.ovpn
OUTPUT=$CONFIG_NAME.ovpn
 
if [ -z "$CONFIG_NAME" ]; then
  echo "\$CONFIG_NAME is empty"
  echo "Please specify client config name. --> exit!"
  exit 1
else
  echo "Make OpenVPN client config for: $CONFIG_NAME"
fi
 
if [ -d $CONFIG_NAME ]; then
  echo "Generating $OUTPUT"
  cat ${BASE_CONFIG} \
    <(echo -e '<ca>') \
    $CONFIG_NAME/ca.crt \
    <(echo -e '</ca>\n<cert>') \
    $CONFIG_NAME/$CONFIG_NAME.crt \
    <(echo -e '</cert>\n<key>') \
    $CONFIG_NAME/$CONFIG_NAME.key \
    <(echo -e '</key>\n<tls-auth>') \
    $CONFIG_NAME/tls-auth.key \
    <(echo -e '</tls-auth>') \
    > $CONFIG_NAME/$CONFIG_NAME.ovpn
else
   echo "ERROR: Folder for $CONFIG_NAME not found --> exit!"
fi
wiki/linux/openvpn.txt · Zuletzt geändert: 2021/12/19 16:56 von wikimaster