Skip to main content

Install and Configure OpenVPN Client

Install OpenVPN client

apt install openvpn -y

Manually connect to OpenVPN server

  • Generate .ovpn file on OpenVPN server and copy to OpenVPN client machine

  • Run the command below to connect:

openvpn --config client.ovpn

Automatically connect to OpenVPN server

  • Generate .ovpn file on OpenVPN server and copy to OpenVPN client machine under /etc/openvpn directory as a .conf file. For example, if you have a my-server.ovpn file you would run the following command:

cp my-server.ovpn /etc/openvpn/my-server.conf
  • Create credentials file in /etc/openvpn/my-server-creds.txt

vi /etc/openvpn/my-server-creds.txt
  • Enter the username and password each one in a separate line like below:

openvpn_username
somepassword
  • Save the file

  • Edit /etc/openvpn/my-server.conf file:

vi /etc/openvpn/my-server.conf
  • Locate the auth-user-pass line in the file and add the credentials file filename next to it like below:

...
auth-user-pass my-server-creds.txt
...
  • Save the file

  • Edit /etc/default/openvpn:

vi /etc/default/openvpn
  • Uncomment the following line (remove the # from the front) :

AUTOSTART="all"
  • Save the file

  • Restart the OpenVPN service on the OpenVPN client:

systemctl restart openvpn
  • Reboot the OpenVPN Client server and ensure it connects automatically