How to Set Up an OpenVPN Server on Linux: Step‑by‑Step Guide
This tutorial walks you through installing required packages, compiling LZO and OpenVPN, configuring environment variables, generating CA, server and client certificates, packaging client files, adjusting server and client configuration files, and finally starting the OpenVPN service on a Linux host.
Install Required Packages
Install the compiler and OpenSSL development libraries:
# yum -y install gcc gcc-c++ openssl openssl-develCompile and Install LZO (compression library)
# wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz
# tar -xzvf lzo-2.03.tar.gz -C /tmp/
# cd /tmp/lzo-2.03
# ./configure --prefix=/usr/local/lzo-2.0.3
# make && make installAdd Library Search Path
Edit the dynamic linker configuration and refresh:
# vim /etc/ld.so.conf
# ldconfigCompile and Install OpenVPN
# wget http://www.openvpn.net/release/openvpn-2.0.9.tar.gz
# tar -xzvf openvpn-2.0.9.tar.gz -C /tmp/
# cd /tmp/openvpn-2.0.9
# ./configure --prefix=/usr/local/openvpn-2.0.9 \
--with-lzo-headers=/usr/local/lzo-2.03/include/ \
--with-lzo-lib=/usr/local/lzo-2.03/lib/
# make && make installCreate Configuration Environment
# mkdir /etc/openvpn
# cp -R /tmp/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
# cd /etc/openvpn/easy-rsa/2.0Set Environment Variables
# vim ./vars
export KEY_COUNTRY=CN
export KEY_PROVINCE="SZ"
export KEY_CITY="shenzhen"
export KEY_ORG="OPEN"
export KEY_EMAIL="[email protected]"Load the variables:
# source ./varsGenerate Certificates
Generate the CA certificate: # ./build-ca Generate Diffie‑Hellman parameters (1024‑bit): # ./build-dh Generate a server certificate (replace servername with your desired name): # ./build-key-serve servername Generate a client certificate (replace clitename with the client identifier):
# ./build-key clitenameDeploy Server Certificates
# cp ca.crt ca.key servername.crt servername.key dh1024.pem /etc/openvpn/Package Client Files
# tar zcvf client.tar.gz keys/ca.* clientname.* /tmp/openvpn-2.0.9/sample-config-files/client.confModify Server Configuration
Edit /etc/openvpn/openvpn.conf to set parameters such as port, protocol, virtual network interface, paths to certificates and keys, DH file, virtual subnet, server subnet, LZO compression, and log file location.
Start OpenVPN Service
# /usr/local/openvpn/sbin/openvpn --daemon --config /etc/openvpn/openvpn.confAdjust Client Configuration
Extract the client package, edit client.conf (rename to .ovpn) and set:
proto tcp
remote VPN‑server‑IP 1194
ca ca.crt
cert clientname.crt
key clientname.key
comp‑lzo
redirect‑gateway def1
When the OpenVPN tray icon turns green, the client is connected.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
