Download raspbian here.
Enable SSH on first boot
To enable SSH on boot, make a file with the name
ssh and no extension and place it in the boot partition. Now we can just use the Pi headless without needing a monitor and keyboard.
- Update the Raspberry Pi
sudo apt-get update sudo apt-get upgrade
- Install OpenVPN
sudo apt-get install openvpn
Download a .ovpn file, this is a configuration file for a specific vpn connection. I am using Windscribe.
Copy this file over to the following location
Now make a new file to save the credentials in.
$ sudo nano /etc/openvpn/cred.txt
Fill in the credentials in this file as follows
Now we need to make a few adjustments to
auth-user-pass "/etc/openvpn/cred.txt" auth-nocache script-security 2 up "/etc/openvpn/up.sh" down "/etc/openvpn/down.sh"
There are two scripts that are called:
DOWNif the VPN loses the connection
UPwhen the VPN is reconnected
We are going to use this to let our torrent program stop/continue downloading based on the state of the VPN.
$ nano /etc/openvpn/up.sh #!/bin/sh echo "Starting Transmission Torrent Downloading" transmission-remote --auth username:password --torrent all --start
$ nano /etc/openvpn/down.sh #!/bin/sh echo "Starting Transmission Torrent Downloading" transmission-remote --auth username:password --torrent all --stop
We also need to give the proper permissions to this file
sudo chmod +x up.sh down.sh
In this article we have installed and configured OpenVPN on a Raspberry Pi. We have also written scripts that are executed when the status of the VPN connection changes.
Thanks for reading! If you have found a mistake, want to ask a question or have a comment, please send me an email.