How to auto-start OpenVPN client in Debian 6 and Ubuntu 12.04 (also works for Debian 7 and Ubuntu 14.04)

Update 2015-04-16: This how to was originally written for Debian 6 and Ubuntu 12.04 but I can assure you that it has been tested with success on Ubuntu 14.04 LTS. Just make sure you really use file client.conf (NOT client.ovpn).

I had this huge problem – my Debian desktop did not reconnect to the VPN on reboot so here is a small how-to what needs to be done :).

Assumptions: You have working installation of OpenVPN client so when you are in /etc/openvpn and type: openvpn client.conf , where your client.conf contains configuration data it does connect without any problems. So now your only problem is – you have to write it every time you need OpenVPN to be connected and this is going to be solved by this howto.

1) Create file  myopenvpn in  /etc/init.d/

nano /etc/init.d/myopenvpn

2) Insert into myopenvpn and save:

# OpenVPN autostart on boot script

start on runlevel [2345]
stop on runlevel [!2345]


exec /usr/sbin/openvpn --status /var/run/openvpn.client.status 10 --cd /etc/openvpn --config /etc/openvpn/client.conf --syslog openvpn

3) Reboot the machine
4) Profit! 🙂