How to auto start openvpn (client) on Ubuntu CLI?
Download the
OpenVPNConfigFile.ovpn
. Note that you can rename the file to anything you like.Move the ovpn file to
/etc/openvpn
cd /etc/openvpn
folder and entersudo nano yourserver.txt
your_server_user_name your_server_passowrd
Save and Close
sudo nano OpenVPNConfigFile.ovpn
Find
auth-user-pass
and addyourserver.txt
next to it so that it becomesauth-user-pass yourserver.txt
This will allow you to skip entering your credentials everytime you start openvpn connection
Rename
OpenVPNConfigFile.ovpn
toOpenVPNConfigFile.conf
sudo mv OpenVPNConfigFile.ovpn OpenVPNConfigFile.conf
sudo nano /etc/default/openvpn
Uncomment
AUTOSTART="all"
sudo service openvpn start
You should see a message saying that you are connected. The connection will be established every time you start your computer.
The openvpn
package comes with an init script /etc/init.d/openvpn
. This script automatically sets up connection for every .conf
(mind the extension) file in /etc/openvpn
.
Found this based on information here: https://openvpn.net/index.php/open-source/documentation/howto.html#startup
If you install OpenVPN via an RPM or DEB package on Linux, the installer will set up an initscript. When executed, the initscript will scan for .conf configuration files in /etc/openvpn, and if found, will start up a separate OpenVPN daemon for each file.
It would be nice to have a un hacker way of doing it, but this will have to do for now.
Create file myopenvpn in
/etc/init.d/
nano /etc/init.d/myopenvpn
Insert into myopenvpn and save:
# OpenVPN autostart on boot script start on runlevel [2345] stop on runlevel [!2345] respawn exec /usr/sbin/openvpn --status /var/run/openvpn.client.status 10 --cd /etc/openvpn --config /etc/openvpn/client.conf --syslog openvpn
SOURCE: How to auto start OpenVPN client in Debian 6 and Ubuntu 12.04