Quick Context
If you’re looking to secure your online activities or connect remote devices to your network, setting up OpenVPN on your VPS is a solid choice. This guide will walk you through the setup process step-by-step.
Step 1: Prepare Your VPS
First things first, let’s make sure your VPS is up-to-date. Connect to your server via SSH and run:
yum update -y
This command ensures that all your packages are updated, which is a good practice before installing new software.
Next, you need to check if the TUN/TAP interface is enabled, which is crucial for OpenVPN to work. Run:
cat /dev/net/tun
If you see cat: /dev/net/tun: File descriptor in bad state, you’re good to go! If not, contact your hosting provider to enable TUN.
Step 2: Install OpenVPN and Dependencies
Now we need to install OpenVPN and its dependencies. Execute the following commands one by one:
yum install gcc make rpm-build autoconf.noarch zlib-devel pam-devel openssl-devel iptables -y
This command installs necessary packages for building OpenVPN.
Next, download the LZO compression package:
wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm
Then rebuild the package:
rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
Now, install the rebuilt package:
rpm -Uvh lzo-*.rpm
Finally, install OpenVPN itself:
yum install openvpn
Step 3: Set Up Easy-RSA
Next, we need to set up Easy-RSA to manage SSL keys. Copy the Easy-RSA directory:
cp -r /usr/share/doc/openvpn-2.2.2/easy-rsa/ /etc/openvpn/
Now, copy the OpenSSL configuration file:
cp -irv /etc/openvpn/easy-rsa/2.0/openssl-1.0.0.cnf /etc/openvpn/easy-rsa/2.0/openssl.cnf
Change to the Easy-RSA directory:
cd /etc/openvpn/easy-rsa/2.0
And set the proper permissions:
chmod 755 *
Now initialize the variables:
source ./vars
./vars
./clean-all
This prepares the environment for generating your certificates.
Step 4: Generate SSL Certificates
You can now proceed to generate your SSL certificates. When prompted, you can fill in your certificate details but leave the password blank by entering .. Run these commands:
./build-ca
./build-key-server server
./build-dh
These commands create the necessary certificates and Diffie-Hellman parameters for your server.
Step 5: Create the OpenVPN Server Config File
Next, we need to create the OpenVPN server configuration file. Change to the OpenVPN directory:
cd /etc/openvpn
Now open the configuration file:
vi server.conf
In this file, you’ll need to add and modify the following lines:
local x.x.x.x # Change this to your server's IP address
port 1194 # Change to the PORT you prefer
proto udp
dev tun
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh2048.pem
To save and exit vi, press [ESC] then type :x.
Final Thoughts
Now you’ve set up OpenVPN on your VPS! Make sure to start the OpenVPN service and check the logs for any errors.
Need more help? Check the latest CrushEdge posts.
No Comments