Without a suitable client configuration, your OpenVPN server remains unreachable for all other devices. In this guide, you build the foundation for it: a clean configuration file for your client that contains all the details for establishing the connection. To do this, you create your own folder structure, adapt a base configuration, and use a helper script that generates the finished .ovpn file at the end.
You need an OpenVPN server that is already running and access to the terminal of the system it runs on. The commands in this guide refer to a Linux environment, such as Ubuntu or Debian in a VirtualBox installation.
Key Takeaways
- The client configuration is a plain text file that bundles all the parameters for the connection to the server.
- The
remoteentry must point to the IP address through which the server is actually reachable. In the local network, this is an internal address; from the outside, it is the public one. - Encryption, authentication, and
key-directionmust match the server configuration exactly. - A helper script inserts certificates and keys into a single .ovpn file. This simplifies distribution to smartphones, tablets, and other computers.
- The folder with the client files contains sensitive keys and should therefore be readable only by you.
Step-by-Step Guide
Step 1: Create a folder structure for the clients
Start with a dedicated directory in which all client files are collected. In the terminal, switch to your home directory and create the main folder with mkdir ~/client-configs. Inside it, create a subfolder with mkdir ~/client-configs/files. The finished .ovpn files will end up there later. This clear separation keeps things organized even when you set up multiple clients.

Step 2: Set access permissions for the folder
The certificates and keys that will later go into the configuration are confidential. Therefore, use chmod 700 ~/client-configs/files to set the permissions so that only you, as the owner, have access. You don't need sudo for this command, because the folder already belongs to your user account.

Step 3: Find the sample configuration in the documentation directory
OpenVPN ships with ready-made templates. They are located under /usr/share/doc/openvpn/examples/sample-config-files/. There, in addition to server examples, you will find the file client.conf, which serves as the starting point for your client configuration. The templates are deliberately extensively commented, so you can read up on the individual options directly in the editor.

Step 4: Copy and rename the template
Copy the file into your client folder with cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/client-configs/. Then rename it with mv ~/client-configs/client.conf ~/client-configs/base.conf. The name base.conf makes it clear that this is the base configuration. All further client profiles will later be created from it.

Step 5: Open the base configuration in the editor
Open the file with nano ~/client-configs/base.conf. Here too, no sudo is needed because the file is in your home directory. Lines that begin with # or ; are comments and therefore inactive. You can recognize active options by the fact that they appear without a comment character at the beginning of the line.

Step 6: Determine the server's internal IP address
Before you can enter the server in the configuration, you need its address. On the server, enter ip addr show eth0; alternatively, ifconfig also works. The address after inet is the IP in the local network. Typical ranges are 192.168.x.x or 10.x.x.x. Such an address is only reachable within your own network, for example in a VirtualBox environment. It is not sufficient for connections from the outside.

Step 7: Clarify the public IP address and port forwarding
If the client needs to access the server while on the go, you need the public IP address of your connection. You can find it out, for example, through a service like whatismyipaddress.com. Enter this address in the configuration later. In addition, you must set up a port forwarding rule on your router for the OpenVPN port so that the requests reach the server.
If you rent a server on the internet, its public address is already the correct one. In this case, the port forwarding is not needed, and you take the address directly from the provider's overview.

Step 8: Set the remote entry to the server address
Look for the line remote my-server-1 1194 in the file. Replace my-server-1 with the address you determined earlier, for example remote 203.0.113.25 1194. Port 1194 stays unchanged, unless you changed it on the server. If the address or port do not match, the connection setup fails already in the first phase.

Step 9: Check the transmission protocol
Check the line proto udp. The protocol must match the server, which also uses UDP. A mismatch, such as TCP on one side and UDP on the other, reliably prevents the connection. So only change something if the server is configured differently.
Step 10: Leave user and group unchanged
The lines user nobody and group nogroup determine under which user account the client process runs. Both settings are sensible for this use case and remain unchanged. As a result, the process runs with as few privileges as possible.
Step 11: Prepare certificate files for embedding
The lines ca ca.crt, cert client.crt and key client.key refer to separate files. Since the script will later write the certificates directly into the .ovpn file, you comment out these three lines by placing a # in front of each. This way you avoid duplicate entries and no longer have to distribute any files.

Step 12: Define encryption and authentication
By default, the template contains a cipher line with GCM encryption, which is not desired for this setup. Comment it out and activate cipher AES-128-CBC instead. Then add the line auth SHA256. These values must match the server configuration exactly, otherwise the server will reject the connection.

Step 13: Set the key direction for the TLS key
Look for the option key-direction. Set it to the value 1. On the server the value is 0, and precisely this opposite direction is required for the tls-auth key. The server must then pass the key on to you so that it can later be integrated into the configuration.
Step 14: Save changes and exit the editor
Save the file with Ctrl + O and confirm the file name with Enter. Then exit the editor with Ctrl + X. Your base configuration is now adjusted. It does not yet contain any certificates and is therefore not a finished client file, but the template for all further profiles.

Step 15: Download the helper script
With a single base configuration, you can generate any number of client files. For this you need the script make_config.sh. Download it with wget. You can find the exact download address in the course description. The file is initially saved as a .txt file, because many platforms otherwise block scripts.

Step 16: Rename the script and make it executable
Remove the .txt extension by entering mv make_config.sh.txt make_config.sh. Then set the permissions with chmod 700 make_config.sh so that you can run the script. Make sure you run the command in the correct directory where the file is located, otherwise the terminal will not find it.

Step 17: Understanding the Structure of the Script
Open the script with nano make_config.sh to understand how it works. It first checks whether the keys are present in the certificate authority's directory. Then it reads in your base configuration and adds the CA certificate, the client certificate, the private key, and the TLS key to it. It saves the result as a single .ovpn file. If the dollar signs and variables in the script are unfamiliar to you, a basic Bash course is worthwhile. You don't need to change anything in the script for this setup. Close the editor without saving, since the file is already complete.
Summary ??? Creating an OpenVPN Client Configuration: Step by Step to the .ovpn File
You now have a customized base configuration that contains your server's address and port, is tuned to the UDP protocol and AES-128-CBC encryption with SHA256, and includes the TLS key with the correct key direction. The certificates are prepared, the permissions of the client folder are secured, and the helper script is ready to go. In the next step, you will use it to generate the finished configuration file for your client.
FAQ
Why is permission 700 sufficient for the folder?With 700, only you as the owner may read, write, and enter the folder. Since the file will later contain certificates and keys, this prevents other users on the system from accessing it.
Do I need sudo to edit the configuration file?No, as long as the file is in your home directory and belongs to you. Sudo would only be necessary if you want to modify system files under /etc.
What happens if I use an internal IP address in the remote entry?Then the client can only reach the server within its own network. For connections from outside, you must enter the public IP address and set up port forwarding on the router.
Why is key-direction set to 1 on the client, but 0 on the server?The direction determines which side takes which role for the tls-auth key. Client and server must complement each other, which is why the two values are opposite.
Do I always have to carry certificates as separate files?No. With an embedded .ovpn file, everything is contained in one file. This is especially practical for smartphones and tablets, because you only have to transfer one file.
What exactly does the make_config.sh script do?It reads in the base configuration, adds the CA certificate, client certificate, private key, and TLS key, and saves the result as a finished .ovpn file.
