1. Log into your Pi and navigate to the command prompt. If you’re using a headless Pi, connect via SSH.
2. Type sudo apt-get install openvpn to install the OpenVPN packages. Type Y and hit Enter if asked to confirm.
3. Navigate to the folder for your OpenVPN configuration files by typing cd /etc/openvpn.
4. Download the configuration files from your VPN provider. In our case we can do this using wget – don’t forget to use sudo as the etc folder isn’t writeable by ordinary users. In our case, the command is sudo wget
https://downloads.nordcdn.com/configs/a ... s/ovpn.zip, followed by sudo unzip ovpn.zip to decompress it.
A quick "ls" command will show if you have been successful. There should be a list of files ending in .ovpn. Note that some VPN providers may have packaged these files with subdirectories, for example for connections encrypted with optional 128bit or 256bit protection. You’ll need to move the files to the etc/openvpn directory using the mv command.
5. Open a connection to any of these servers using the command sudo openvpn example.ovpn –daemon where "example" is the filename of the configuration file. If you try this now, you’ll notice that the script asks for your username and password to authenticate the connection. Do test to see if the connection is working by typing ifconfig. You should see a connection marked "TUN", which is your VPN tunnel.
Stop Entering Passwords
So far we have a slightly cumbersome way of connecting our Pi to a VPN via a terminal which requires you to enter your username and password when you want to connect. Good, but it could be better – we’re going to create a few scripts to automatically create your credentials.
Take a look at the VPN files you downloaded to your desktop and open one of them. You should see that it starts with client and that there’s a list of commands. These include a line that contains "auth-user-pass". We can alter this line to automatically feed a username and password to our config file when it is called.
1. Navigate to /etc/openvpn and type sudo nano vpnlogin. This should open up the nano text editor.
2. Create a text document that has nothing except your username for the VPN provider on the first line, and your password on the second.
3. Hit CTRL+O to write the contents to disk, then CTRL+X to quit nano.
4. Pick the VPN connection you think you’ll use the most and edit the config file using sudo nano example.ovpn.
5. Change the line that says "auth-user-pass" to "auth-user-pass vpnlogin".
Now when you start that connection using the "openvpn" command, it should connect directly without the password prompt. (See boxout to change all the config files at once.)
Hope this helps!
Regards,
Lewis