This project provides a script and systemd service to automatically connect to a ProtonVPN server at startup on a Linux system. The script randomly selects a VPN configuration file from a specified directory and connects to the VPN using OpenVPN with provided credentials.
- Python 3
- OpenVPN
- ProtonVPN account
Clone the repository to your local machine:
git clone https://github.com/sfndiku/automaticVPN.gitMake sure Python and OpenVPN are installed
in Ubuntu and other debian based systems:
sudo apt install python3 python3-pip openvpnin Arch Linux:
sudo pacman -S openvpn pythonin CentOS/RHEL:
sudo yum install python3 python3-pip openvpnin Fedora:
sudo dnf install python3 python3-pip openvpnPlace your ProtonVPN configuration files (.ovpn) in the configs directory within the cloned repository. In order to do this:
- You need to have a ProtonVPN account
- Sign in to your account
- go to account page, click on Downloads, scroll down to OpenVPN configuration files
- Choose the platform, protocol(most likely UDP), and click free server configs(assuming you do not have a paid subscription)
- Download the necessary configuration files which suite you at least 5
- Put those files in the config directory within you cloned repository for simplicity.
Edit the connect_vpn.py script to set the path to your VPN configuration files:
VPN_CONFIG_DIR = '/path/to/config/files' # Change this to the path where your .ovpn files are stored which is the config folder within the cloned repoTo securely store your ProtonVPN credentials, set the environment variables in the systemd service file. How? I'll tell you how.
-
I have given the .service file in this repo, copy that and put it in the /etc/systemd/system/ folder.
-
Now in the .service file's line
ExecStart=/usr/bin/env python3 /path/to/your/.py/file
change the path of the .py file to your actual .py file which is in the cloned repo (connect_vpn.py)
-
Replace your_actual_username and your_actual_password in the .service file with your ProtonVPN credentials which you can get in the accounts page of protonvpn in OpenVPN / IKEv2 username section
Make the connect_vpn.py script executable:
chmod +x /path/to/your/connect_vpn.pywhich will be in your cloned repo.
Enable and start the systemd service:
sudo systemctl daemon-reload
sudo systemctl enable connect_vpn.service
sudo systemctl start connect_vpn.serviceGo to DNS leak test site and check your DNS
Reboot your system and check dnsleaktest.com
Contact me via email sfnbusiness01@gmail.com.
PS. feel free to modify and use it for your own requirements