From 3de0e07e86335eb04002344fe6cefae48d6fd0f7 Mon Sep 17 00:00:00 2001 From: Ivaylo Tsankov Date: Wed, 25 Oct 2023 19:16:05 +0300 Subject: [PATCH] * Add Makefile for client ovpn generation --- content/blog/openvpn-server-setup.md | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/content/blog/openvpn-server-setup.md b/content/blog/openvpn-server-setup.md index 0a7d8ad..d2db798 100644 --- a/content/blog/openvpn-server-setup.md +++ b/content/blog/openvpn-server-setup.md @@ -324,6 +324,54 @@ popular vpn clients that support OpenVPN: Now you are good to go! You can surf the internet securely. +## (Optional) Gift +If you don't want to re-read this tutorial to issue client configurations once +in a while because you don't remember and command exec sequence, here is a quick +`Makefile` that will simplify the creation of a client configuration. +1. Go to `/path/to/openvpn-ca` +3. `vim Makefile` +4. Paste the following content: +```sh +SHELL := /bin/bash + +CLIENT ?= client1 +EASYRSA_DIR ?= . +PKI_DIR ?= $(EASYRSA_DIR)/pki +TA_KEY ?= $(EASYRSA_DIR)/ta.key +OUTPUT_DIR ?= $(EASYRSA_DIR)/clients +OVPN_TEMPLATE ?= $(OUTPUT_DIR)/client.ovpn.template + +.PHONY: help client + +help: + @echo "Usage:" + @echo " make client CLIENT=" + @echo " Generates an OpenVPN client configuration file for the specified client." + @echo " If is not provided, 'client1' is used as the default." + +client: + @mkdir -p $(OUTPUT_DIR) + + @$(EASYRSA_DIR)/easyrsa build-client-full $(CLIENT) nopass + + @cat $(OVPN_TEMPLATE) > $(OUTPUT_DIR)/$(CLIENT).ovpn + @echo -e "\n$$(cat $(PKI_DIR)/ca.crt)\n\n\n$$(cat $(PKI_DIR)/issued/$(CLIENT).crt)\n\n\n$$(cat $(PKI_DIR)/private/$(CLIENT).key)\n\n\n$$(cat $(TA_KEY))\n" >> $(OUTPUT_DIR)/$(CLIENT).ovpn + + @echo "Client configuration for $(CLIENT) created at $(OUTPUT_DIR)/$(CLIENT).ovpn" + +default: help +``` +5. Save and exit + +Whenever you need to issue a new client configuration you can just run: +```sh +make client CLIENT= +``` + +If you forget the `make client CLIENT=` command execution, just run `make` and it will +print you the help section. + + ### Troubleshooting 1. If you receive similar messages on the server side: ```