OpenVPN Setup Tutorial
Installation
Via source code
Download tar ball from release link
Dependencies
1
2apt install libssl-dev liblzo2-dev libpam0g-dev
apt install easy-rsaBuild source code
1
2
3
4
5tar xfz ./openvpn<version>.tar.gz
cd openvpn<version>
./configure
make
make install
Via official apt repositories
1 | wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg|apt-key add - |
Via script
1 | curl -O https://raw.githubusercontent.com/Angristan/openvpn-install/master/openvpn-install.sh |
Setup
CA
1 | make-cadir CA && cd CA |
In CA directory, edit the vars file and set the KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG and KEY_EMAIL parameters.
1 | source ./vars |
Key generation
In keys directory, generate the private keys, certification and Diffie Hellman parameters.
- Server key generation
1
./build-key-server server
- Client key generation
1
2
3./build-key client1
./build-key client2
./build-key client3 - Diffie Hellman parameters generation
1
./build-dh
Here is an explanation of the relevant files in keys subdir:
Filename | Needed By | Purpose | Secret |
---|---|---|---|
ca.crt | server + all clients | Root CA certificate | NO |
ca.key | key signing machine only | Root CA key | YES |
dh{n}.pem | server only | Diffie Hellman parameters | NO |
server.crt | server only | Server Certificate | NO |
server.key | server only | Server Key | YES |
client1.crt | client1 only | Client1 Certificate | NO |
client1.key | client1 only | Client1 Key | YES |
Configuration
- In VPNServer, put server.conf, ca.crt, server.crt, server.key and dh{n}.pem in the same directory(e.g. /etc/openvpn/).
- In Client, put client.conf, client{n}.crt, client{n}.key and ca.crt in the same directory.
- In client.conf, modify the remote value to VPNServer’s IPv4 address, modify cert and key to corresponding filename.
Running
- In VPNServer:
1
openvpn --config /etc/openvpn/server.conf --daemon
- In Client:
1
openvpn --config /etc/openvpn/client{n}.conf --daemon