How to Automatically Run NordVPN on Startup in Linux with Preferred Country and City
I have several VPNs on my speed demon, but I always have to manually start them up when I log in. It would be nice to have them run automatically whenever I log in. For the experienced Linux users out there, this article will show you how to setup NordVPN to automatically start whenever you log in to your PC or Raspberry Pi.
Edit Your Profile In Order To Use The Free Version
In order to use the free version of NordVPN, you will need to edit your profile in the app. Navigate to the profile tab and click on the Edit Profile button. You will need to put in your email, country, and a personal keyword. In my case, I put in my email address, country of residence, and the word “geek”. Once you enter this information, a verification email will be sent to you. Once you verify your email, you can download and install the app.
Install The NordVPN CLI On Your Raspberry Pi
Once you have downloaded the zip file, unzip it to your desktop. Inside the unzipped folder you will find several files. You will need to install the NordVPN client on your Raspberry Pi. Use the following command to install the app:
sudo apt install client-nordvpn-cli
Configure Your Account In The NordVPN App
Once you have downloaded and installed the app, you can open it up and click on the Connect button to connect to a VPN. You will need to login to your account in the app and authorize the installation of the app on your device. Then you can click on the Done button to continue to the setup wizard.
The next step is to provide the app with your country, city, and the type of device you are using. After you fill out this information, the app will automatically detect your Internet service provider and will offer you to connect to a VPN that is optimized for your location.
Configure Your Internet Service Provider In The NordVPN Setup Wizard
In the Setup Wizard, you will need to enter your information again, but this time you will select Internet Service Provider (ISP). After you fill in your country, city, and ISP information, click on the Continue button to continue to the next step.
The Setup Wizard will walk you through the process of configuring your Internet Service Provider (ISP) with your preferred city and country. This step is optional, but I find it helpful to know my preferred country and city when connecting to VPNs. You will have the option to connect to a US-only VPN, which will not offer any international connections. However, if you want to use a VPN that covers a few countries, you can select one from a list of providers that are recommended for your region. Then, click on the Save button to continue to the next step.
Configure Your Email In The NordVPN Setup Wizard
You can connect to one of the provided VPNs by entering your email address in the form below:
email@example.com
Then, click on the Continue button to continue to the next step.
Now that you have entered your email address, the app will send you a confirmation email with a link to click on. Once you click the confirmation link, you will be taken to a page that allows you to verify your email address.
After you confirm your email, you will be shown a page that contains your email address and a verification code that you can type in below:
email@example.com
Then, click on the Continue button to continue to the next step.
Configure Your Computer To Automatically Start The NordVPN Service On Boot
NordVPN is a Linux-based app, so you will need to setup the service to automatically start whenever you reboot your computer. This can be done from within the app or by editing your /etc/rc.local script. Since I use Raspberry Pi 3s as my desktop computers, I will show you how to do this from the app.
Navigate to the profile tab in the app and click on the Edit Profile button. Then, scroll down to the Startup section and click on the Edit button. A pop-up window will appear with your current settings. Just above the settings, you will find a section labeled Startup. Click on the Configure button to open a new window with all the configurations available for you to choose from.
Search for the term “bootanimation” in the search bar above and you will see that several options exist. Choose the one that you would like to use and click on the Continue button to continue to the next step.
Add A Startup Script To Automatically Start The NordVPN Service On Boot
Now, you will need to create a startup script that automatically starts the NordVPN service on boot. First, let’s start by making sure you are using the correct Linux distribution and version. On the left side of the screen, you will see a list of all the distributions available for download. Choose the one that you are using and click on the Back icon to return to the previous screen.
Then, click on the File button and navigate to the /etc/ folder. In this folder you will see several other folders and files. Find the folder labeled “init” and open it up. In the init folder, you will see a number of scripts that can be executed on startup.
The script you will use to start the VPN is named “init.service” and you will want to save this file with a.service extension at the end of the name. Then, click on the Save button to continue to the next step.
Make Sure Your Computer Has Ansible Installed
We will now have to make sure that your computer has Ansible installed. Ansible is a tool that allows you to easily configure and automate the configuration of a server. Let’s assume that you have Ansible installed on your computer already. Then, you can proceed to the next step.
Run The Following Commands To Open Up A Tunnel To Your VPN
Now that you have your VPN configured and started automatically on boot, you can open up a tunnel to connect to it. The following commands will do this for you:
ssh -f -N -L [email protected]:59.88.0.0:1194 -i /etc/ssh/my_id_rsa -D 59.88.0.0:1194 User@example.com
First, you will want to open up an ssh connection to your Raspberry Pi using your private key with the following command:
ssh -f -N -L [email protected]:59.88.0.0:1194 -i /etc/ssh/my_id_rsa -D 59.88.0.0:1194 User@example.com
Then, you will want to connect to the VPN using the command below:
ssh -f -N -L 59.88.0.0:1194:localhost:5984 -i /etc/ssh/my_id_rsa -D 59.88.0.0:1194 User@example.com
Now, when you login to your Raspberry Pi, you will see that the VPN is active and that the IP address of your computer has changed. When you open up a web browser on the Raspberry Pi, you will see that it is now accessible from anywhere on the Web:
HTTP://[email protected]:59.88.0.0:5984
To disconnect from the VPN, you can run the following command:
ssh -f -N -L 59.88.0.0:5984 -i /etc/ssh/my_id_rsa -D 59.88.0.0:1194 User@example.com
Or, you can just close the computer lid to terminate the connection.
As mentioned before, you will find several scripts in the /etc/init folder. If you want to stop the script from running on startup, you will need to comment out the relevant lines in the startup scripts.