pia.sh - Fully featured unofficial Linux PIA client written in bash
Hi all,
Just a heads up if anyone wants a fully featured client that works on any Linux:
Linux pia client v 0.2
Any feedback or suggestions welcome!
Cheers
Just a heads up if anyone wants a fully featured client that works on any Linux:
Linux pia client v 0.2
Any feedback or suggestions welcome!
Cheers

Comments
feedback:
consider adding a start at boot switch (maybe by setting a crontab).
┈┈┈┈┈┈▕▔╲
┈┈┈┈┈┈┈▏▕
┈┈┈┈┈┈┈▏▕▂▂▂
▂▂▂▂▂▂╱┈▕▂▂▂▏
▉▉▉▉▉┈┈┈▕▂▂▂▏
▉▉▉▉▉┈┈┈▕▂▂▂▏
▔▔▔▔▔▔╲▂▕▂▂▂▏
the quoting on the echo to create the resolv.conf contents looks mad complicated. have you encountered the use of inline input redirection (aka "here" input) ?
Cheers bud, script should work on any linux distro with a bash shell, and also works automatically (installing dependencies) on debian and arch based distros (ubuntu, kali, mint, antergos etc etc). For any other linux just install openvpn and ufw and it will work.
@ratJuice
Thanks for trying it out, pushed a few updates since you posted so you might want to git pull and run with a -u to make sure you are compatible with the new version. I don't plan to implement any startup methods as the script is designed to be run in a terminal so you can shut down the VPN and restore all settings whenever you like and also see all the relevant information such as forwarded port.
@martouf
Thanks for taking a look at the script. The -s switch is meant to be run with a number, just like in the example. It is much quicker than typing in the full name of the location. You can see the numbers with the corresponding full place names by running with -l switch. About the echo for the resolv.conf, it isn't complicated at all it is called triple quoting and it is how i prefer to echo multi line strings. Whichever way works for you is cool, that's whats so great about bash, many ways to skin a cat:
Completely open source and under 500 lines of easy to understand bash code.
Enjoy!
- PIA MACE
- Internet Killswitch
- Improved code optimization and readability
NOTE: users of previous versions must run with -u once after updating to make your configuration files compatible.Take a look at the script, it's clearly a fully featured client that does everything the official one does.
And no, you cannot do what this script does with only openvpn in any reasonable amount of time.
So yes, I will call this a client.
And no I didn't rewrite openvpn for the sake of a bash script, I think the official client must run on top of openvpn too, rewriting massive VPN clients is not one of the brightest ideas, security wise.
Here is the verbose output. It just stays at "Fetching IP" forever.
Do you have curl installed on your system?
I have edited the script so if you want to download the new version from github it should check for curl and install if it is missing.
Also it will give up fetching the IP after two tries so no hang up.
Thanks again, any other bugs let me know and I will fix asap.
I do have curl installed. I installed it after reading the README and before running the makefile.
Also do you know what the
line is referring to in the output? I tried your script because my normal setup is inexplicably failing using network-manager after 16 months of working. I'm wondering if it might be related. Googling it takes me on a deep dive of OpenVPN bugs that is out of my depth.
Thanks.
That line is an old openvpn bug, it doesn't affect the security of the connection in any way and there is no way to fix it unless they fix it within the openvpn code.
Seeing as you have curl installed, that means that either your DNS is not answering requests or you cannot curl icanhazip.com for some reason. The ip fetching works every time on my own system, but it is not essential and should not affect the rest of the script, but it is a little strange.
Try running
from the command line before connecting, it should output your IP address.
Nice work!
I have verified that the file crl.rsa.4096.pem is present in the /etc/openvpn/pia directory, and that root has read permissions:
Been troubleshooting for a while but can't seem to figure it out. Any help would be greatly appreciated!
You're damn good, man. I've been living with archlinux for years and love your script. I usually insist that everthing I install is done via pacman, but I installed your script the old fashioned way and it works extremely well. Thank you for making our lives a little bit easier.
1) The CRL file path is not specified in the script, it is specified in the ovpn configuration file downloaded from PIA. This means that each file for the individual servers must be modified.
2) If the script is run with the -u option, these changes are undone, and all the files must be edited again.
It seems that OpenVPN will not look for the CRL in the same directory as the ovpn file when the path is not specified (which I feel like it should). Oddly, even adding a ./ in front of the CRL file name didn't work, it had to be the full absolute path. Even more strange is that OpenVPN seems to have no problem finding the CA file which is also included in the same directory. I looked around to see if there was an environment variable that could be set, and even tried adding /etc/openvpn/pia to my path, but neither of these approaches worked.
If we could find a way to make this work without having to manually edit every ovpn file, that would be the ideal solution.
you don't really need to manually edit all the files:
ps: it's generally a rule the full path to a config file should always be specified, even if part of it is contained in an environment variable or a string constant like $CONFIGDIR/config.file
This is exactly what I need (Enter the login only once and select from various connection types).
Unfortunately the version 0.2 script is not working for me. I have tried this on two separate laptops, one running Linux Mint 18.2 Mate and the other running Linux Mint 18.2 Cinnamon:
Downloaded everything and ran:
./pia.sh
I get the following errors after selecting the server to connect to:
pjc123, the crl issue isn't really a problem with the script, it's an openvpn thing. I was able to fix this by adding a new function at the top of the script, containing a modified version of martoufs' sed loop. What worked for me is:
Then you just need to call it at the end of the fupdate function, like so:
I later found that the script keeps creating new tunnel interfaces everytime you turn it off and back on, in order to resolve this I added another loop inside of fvpnreset, like so:
for i in $(lsof -i | grep openvpn | awk '{ print $2 }'); dokill -9 $i
done echo "$INFO VPN Disconnected."
Finally, I noticed that the permissions on my pass.txt file had somehow been set to 0644 along the way, I just fixed it manually but something you may want to look out for.
After making these changes, the script now seems to be working just fine, and I'm passing all the leak tests.
Thanks again to martouf for helping me figure this out, and a big thanks to d4rkcat for writing the original script.
Looks like some people have a different bash shell that doesn't like
which i thought was pretty standard bash syntax.
I will edit the script to include full pathnames in the ovpn files but i really don't like that solution and don't see why it needs to be done.
Give me until 6pm GMT and i will have a new version.
Cheers
Just run pia with a -u to update your ovpn files.
Also included @hexsorcerer fix to make sure openvpn is killed.
Let me know if anything else needs fixing.
Cheers
EDIT: Also feel free to fork and submit pull requests then fixes can be integrated much easier and that way you get credit
correctly, then one of these is true: it isn't really bash (busybox?), bash is broken, or cmd1 isn't playing by the retval rules
@d4rkcat someone ran into problems because they mounted their fs nosuid .. perhaps there's another mounting nosymfollow ?
Yes, agreed it's something that works on every linux distro i've ever used and i'm pretty sure all bash shells must do that.
If you look at line 368 in the commit I pushed today:
So you shouldn't need to run the script from $VPNPATH or edit the config files because the subshell should already be running the command from $VPNPATH.
That line has always been like that and worked well for me on arch, but many of the people who have problems say the problems are path related.
In any case, my fupdate function has been updated now to edit the ovpn files and add the full paths to all relevant files.
About running things nosuid; that's never going to work because openvpn and ufw requires root to modify the network stack so I won't be supporting anyone who doesn't run as root.
[X] 32 is not valid! 1-0 only.
that should not happen, something is going wrong with line 326:
can you run from a terminal:
and paste the output?
What OS are you using?
Are you running as root?
Is there anything non-standard about your system?