5

I have a server with OpenVPN installed on it, and I also have laptops (clients) running Ubuntu with openvpn installed. On the client, if I manually run the command "sudo openvpn /etc/openvpn/client.conf" the client is configured to prompt me for login info (username and password) which it will then use in authentication with the server. I would like this process to happen automatically on startup. Basically, I need logging into the client laptop and logging into the openvpn server to be the same action. I want the the authentication information for logging into openvpn to be the same as the login information for logging into the laptop's local user account. How can I do this?? Details please.

2
  • Does it have to be Username/Password? I know you can do this via pubkey auth on /etc/network/if-up.d Jun 1, 2016 at 20:43
  • What would the method you are talking about entail?
    – Tommy Orok
    Jun 1, 2016 at 20:59

3 Answers 3

9

I assume You have downloaded an .ovpn file with the information about the vpn.

Create a file in the same folder called auth.txt and insert in its first line the username of your vpn login, in second line the vpn password, e.g.:

admin
master

Save the file and close it. Edit Your .ovpn file: find the line starting with auth-user-pass and add auth.txt. Save the file and close it.

enter image description here

I would write the full path to auth.txt e.g. auth-user-pass /etc/openvpn/auth.txt but (at least on Ubuntu) it also works with just the filename, if in the same folder.

Now You should be able to call sudo openvpn <.ovpn file> without providing credentials (apart from the sudo password).

I based information on here and here

There is a small note how to autorun scripts on system boot: here

2

Use "auth-user-pass credentials-file.txt" option in your client config file. The credentials file should be in the form:

username
password

Yes, you will have the plaintext file with username and password.

2
  • Thank you so much for your reply, but that only tells me how I would take care of the automatic authorization part. How do I configure openvpn to start upon login in the first place?
    – Tommy Orok
    Jun 2, 2016 at 10:30
  • Try to run it from bash-profile or so. Implement locking to not to run it more than once. Jun 8, 2016 at 6:02
1

For any modern Ubuntu version (16.04+), save your OpenVPN client configuration file as /etc/openvpn/<name>.conf and run

# systemctl enable openvpn@<name>.service

This will create a startup unit from the template provided by the installed openvpn package.

(Alternatively, if you want to distinguish between server and client connections, place .conf file into .../client/ or .../server/ subdirectory and use, respectively, openvpn-client@ or ...-server@ template to create startup uint.)

Try to start the newly created service - systemctl start openvpn@<name>. You will see broadcasts about username and password requirements and TTY popups to fill in the missing data. Enter the data and check that tunnel is up and running.

Then create authorization file as outlined in the other answers and restart the service to see if the data is filled in automatically.

Worked just fine for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .