manually run openVPN inside a screen terminal

Hi there,

I'm trying to create a script that runs in terminal is automatically started in a raspberry pi 'screen' output. The problem here is that i need sudo privileges inside the script, and that once the process is running I don't see the request for the password.

one example of how the script should run is the following:
1) go to a folder:
cd /etc/openvpn
2) execute the service (this requires sudo privileges):
sudo openvpn ./pia_netherlands.conf
When I enter the code manually the script does run so there is no problem there, I just have a problem executing this inside a 'screen'

I've set up the following script using some googleing:
#!/bin/sh
if [ -z "$STY" ]; then exec screen -dm -S pia /bin/bash "$0"; fi
cd /etc/openvpn
sudo openvpn ./pia_netherlands.conf
This script should check if there is a screen called 'pia' and if not create a screen called pia and run the script.

It however does not seem to work, can anyone maybe suggest where I should go from here?

Thanx in advance.

Comments

  • Easy, just edit the ovpn file and where it says
    auth-user-pass
    Change it to 
    auth-user-pass pass.txt
    Then place a file called pass.txt in the same directory as the ovpn file which contains:
    yourusername
    yourpassword


    You could also try my script which does all this for you.

    Cheers

  • Is there any reason you want to run this in screen at all?

    On most recent Linux distros, you can drop the VPN configuration files directly in /etc/openvpn/client/, rename the one you want to use to .conf and just start/enable it as a system service With systemd that would be "sudo systemctl enable --now [email protected]", and that would automatically load up /etc/openvpn/client/pia.conf in OpenVPN for you.
Sign In or Register to comment.