{"id":1822,"date":"2023-10-29T22:58:03","date_gmt":"2023-10-29T17:28:03","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=1822"},"modified":"2025-04-15T15:43:35","modified_gmt":"2025-04-15T10:13:35","slug":"guide-to-securing-linux-production-servers-using-openvpn","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/guide-to-securing-linux-production-servers-using-openvpn\/","title":{"rendered":"Guide to Secure Linux Production Servers using OpenVPN"},"content":{"rendered":"\n<p>If you\u2019ve stumbled upon this guide, you\u2019re probably looking to enhance your organization\u2019s security by securing your production servers, just like I did a while ago. I&#8217;m here to walk you through setting up a VPN using OpenVPN, based on my experience. Let\u2019s get started, shall we?<\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"architectural-overview\">Architectural Overview<\/h4>\n\n\n<p>Initially, we used a less secure practice of directly logging into our servers. In order to improve security, we have transitioned to a more robust approach by implementing OpenVPN servers and instances. In this approach, we are setting up a VPN service on one server and a separate Jump server for secure access to the production servers\/services.<\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h4>\n\n\n<p>A server instance with Almalinux 8.x installed.<\/p>\n\n\n\n<p>Necessary credentials and privileges to access and configure the server.<\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"openvpn-server-configuration\">OpenVPN Server Configuration<\/h4>\n\n<h5 class=\"wp-block-heading\" id=\"1-initial-setup\">1. Initial Setup<\/h5>\n\n\n<p><strong>Login<\/strong>: Connect to your server instance with appropriate user credentials.<\/p>\n\n\n\n<p><strong>Superuser Access<\/strong>: Switch to superuser for administrative tasks:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo su<\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"2-server-configuration-initialization\">2. Server Configuration Initialization<\/h5>\n\n\n<p>Run the command below to initialize or reinitialize the server configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ovpn-init --force<\/pre>\n\n\n\n<p>Follow on-screen instructions, opting for default settings when prompted.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"3-user-password-setup\">3. User Password Setup<\/h5>\n\n\n<p>Set a secure password for the default &#8216;openvpn&#8217; user:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">passwd openvpn<\/pre>\n\n\n<h5 class=\"wp-block-heading\" id=\"4-admin-panel-access\">4. Admin Panel Access<\/h5>\n\n\n<p>Access the OpenVPN admin panel through your browser at <code>https:\/\/[your-server-ip]:943\/admin<\/code>.<\/p>\n\n\n\n<p>Log in using the &#8216;openvpn&#8217; user credentials.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"5-hostname-and-dns-configuration\">5. Hostname and DNS Configuration<\/h5>\n\n\n<p>Update your DNS settings to point your server IP to your desired subdomain.<\/p>\n\n\n\n<p>Update the server&#8217;s hostname with the below command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hostnamectl set-hostname [your-subdomain]<\/pre>\n\n\n\n<p>Reflect this change in the OpenVPN Admin Panel under <code>Configuration &gt; Network Settings<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2023\/10\/step6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"378\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2023\/10\/step6-1024x378.png\" alt=\"Setting up hostname in openvpn\" class=\"wp-image-1876\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step6-1024x378.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step6-300x111.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step6-768x284.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step6.png 1476w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"6-licensing\">6. Licensing<\/h5>\n\n\n<p>Purchase and activate a license for OpenVPN Server from the <a href=\"https:\/\/openvpn.net\/access-server\/pricing\/\" target=\"_blank\" rel=\"noopener\">official OpenVPN pricing page<\/a>.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"7-user-management-for-client-vpn\">7. User Management for Client VPN<\/h5>\n\n\n<p>In the Admin Panel, navigate to <code>User Management &gt; User Permissions<\/code>.<\/p>\n\n\n\n<p>Create a new user and configure as needed, ensuring the &#8216;Auto-login&#8217; option is enabled if necessary.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"8-multifactor-authentication-optional\">8. Multi-Factor Authentication (Optional)<\/h5>\n\n\n<p>If desired, enable Google Authenticator MFA from the <code>Authentication<\/code> tab.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"9-ssl-certificate-configuration\">9. SSL Certificate Configuration<\/h5>\n\n\n<p>Generate a CSR and private key on your server.<\/p>\n\n\n\n<p>Obtain an SSL certificate from your preferred provider and upload it through the Admin Panel under <code>Configuration &gt; Webserver<\/code>.<\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"10-configuration-and-user-profile\">10. Configuration and User Profile<\/h5>\n\n\n<p>Save all changes and update the running configuration as prompted.<\/p>\n\n\n\n<p>Download the user profile for VPN access from <code>https:\/\/[your-configured-subdomain]<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2023\/10\/step11.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"262\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2023\/10\/step11-1024x262.png\" alt=\"Upade configuration in openvpn\" class=\"wp-image-1877\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step11-1024x262.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step11-300x77.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step11-768x196.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step11-1536x393.png 1536w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/step11.png 1862w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><br><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"jump-server-configuration\">Jump Server Configuration<\/h4>\n\n<h5 class=\"wp-block-heading\" id=\"1-allow-only-vpn-ip\">1. Allow only VPN IP<\/h5>\n\n\n<p>If you are using a cloud instance as a Jump server, you can configure security by configuring firewall rules within the security panel to permit connections exclusively from the VPN&#8217;s IP address to the Jump Server instance. This ensures that only authorized VPN connections can access the Jump server, bolstering your network&#8217;s security.<br><br>For example, if you are using an AWS instance as a Jump server, follow the following steps:<br><\/p>\n\n\n\n<p class=\"has-black-color has-ast-global-color-8-background-color has-text-color has-background\">1.  <strong>Log in to the AWS Management Console<\/strong>:Sign in to your AWS account using your credentials.<br><br>2. <strong>Navigate to the EC2 Dashboard<\/strong>:Once logged in, go to the EC2 dashboard.<br><br>3. <strong>Select the Jump Server Instance<\/strong>:In the EC2 dashboard, select the Jump server instance for which you want to configure security group rules.<br><br>4. <strong>View the Security Group<\/strong>:In the details pane at the bottom, under the &#8220;Description&#8221; tab, you&#8217;ll find the security group associated with the selected Jump server instance. Click on the security group name to access its configuration.<br><br>5. <strong>Edit the Inbound Rules<\/strong>:In the security group details, go to the &#8220;Inbound rules&#8221; tab.<br><br>6. <strong>Add a New Rule<\/strong>:Click the &#8220;Edit inbound rules&#8221; button, then click &#8220;Add rule&#8221; to create a new rule.<br><br><strong>Specify the Rule<\/strong>:<br>Set the rule as follows:Type: Choose the appropriate protocol and port(s) for the service you want to allow. For example, if it&#8217;s SSH, select &#8220;SSH (22)&#8221; or customize it according to your application&#8217;s needs.<br>Source: Enter the IP address or IP range of your VPN service. You can specify a single IP, a range, or a specific security group associated with your VPN server.For example, if your VPN server&#8217;s IP is 1.2.3.4, you can enter &#8220;1.2.3.4\/32&#8221; to allow only that specific IP.<br><br>7. <strong>Review and Save<\/strong>:Review the rule settings to ensure they are correct, and then click &#8220;Save rules.&#8221;<br><br>8. <strong>Confirm the Changes<\/strong>:AWS will prompt you to confirm the changes. Click &#8220;Save rules&#8221; again to apply the new security group rule.<\/p>\n\n\n\n<p>If you are using an on-premise server or VPS as the Jump server, you can configure the necessary firewall rules directly within the firewall management tools available on that server or VPS.<br>Refer Docs: <a href=\"https:\/\/askubuntu.com\/questions\/615343\/allow-ubuntu-server-access-only-from-specific-ips\" target=\"_blank\" rel=\"noopener\">Ubuntu<\/a>, <a href=\"https:\/\/access.redhat.com\/solutions\/260463\" target=\"_blank\" rel=\"noopener\">Redhat<\/a>, <a href=\"https:\/\/www.transip.eu\/knowledgebase\/entry\/4801-restricting-remote-desktop-specific-addresses\/\" target=\"_blank\" rel=\"noopener\">Windows<\/a><\/p>\n\n\n<h5 class=\"wp-block-heading\" id=\"2-implement-ssh-keys\">2. Implement SSH Keys<\/h5>\n\n\n<p>Generate an SSH Key Pair by using the &#8216;ssh-keygen&#8217; command, which will create a key pair. Share the Public Key by sending the contents of the &#8216;id_rsa.pub&#8217; key file to the production server and appending it to the &#8216;\/.ssh\/authorized_keys&#8217; file. Finally, test the SSH key by attempting to log in with &#8216;ssh user@remote-server&#8217; for secure and passwordless access. These steps ensure a streamlined and secure connection process between your local and remote machines.<\/p>\n\n\n\n<p>Refer Doc: <a href=\"https:\/\/www.veeble.org\/kb\/ssh-login-without-password\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.veeble.org\/kb\/ssh-login-without-password\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"production-server-configuration\">Production Server Configuration<\/h3>\n\n<h4 class=\"wp-block-heading\" id=\"1-ssh-configuration-in-your-servers\">1. SSH Configuration in your Servers<\/h4>\n\n\n<p>Modify the SSH daemon configuration to disable password authentication:<\/p>\n\n\n\n<p>This file is typically located at <code>\/etc\/ssh\/sshd_config<\/code>. You can use a text editor like &#8216;nano&#8217; or &#8216;vim&#8217; to edit the file:<em><br><code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PasswordAuthentication no <\/pre>\n\n\n\n<p>Restart the SSH service to apply changes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">service sshd restart<\/pre>\n\n\n\n<p class=\"has-text-align-left has-black-color has-ast-global-color-8-background-color has-text-color has-background\">If your clients are granted access to the server through separate user accounts provided to them, you have the option to disable root user login as an alternative to disabling PasswordAuthentication as previously mentioned. Disabling root login enhances security by preventing direct root access to the server. Here are the steps to execute this on a Linux server: <br><br>1. <strong>Login as a Superuser<\/strong>: Start by logging into your server as a superuser or with superuser privileges using the command <code>sudo<\/code>.<br><br>2. <strong>Create an Alternate User Account<\/strong>: Create a new user account that your clients will use to access the server. You can create a new user named &#8216;clientuser&#8217; with the following command:<em><br><code>sudo adduser clientuser<\/code><br><\/em><sub>Follow the prompts to set a password and provide any required information.<\/sub><br><br>3. <strong>Grant Sudo Permissions<\/strong>: To allow the new user to perform administrative tasks, you can grant them sudo permissions. Add the user to the &#8216;sudo&#8217; group using the following command:<br><em><code>sudo usermod -aG sudo clientuser<\/code><\/em><br><em><br><\/em>4. <strong>Test the New User Account<\/strong>: Log out of the root account and log in as the new user to ensure that it has the necessary permissions:<em><br><code>su - clientuser<\/code><br><\/em><sub>You should now be logged in as &#8216;clientuser&#8217;.<\/sub><br><sub><br><\/sub>5. <strong>Disable Root Login<\/strong>: To disable direct root login, open the SSH configuration file in your preferred text editor. This file is typically located at <code>\/etc\/ssh\/sshd_config<\/code>. You can use a text editor like &#8216;nano&#8217; or &#8216;vim&#8217; to edit the file:<em><br><code>sudo nano \/etc\/ssh\/sshd_config<\/code><br><\/em><sub>Inside the configuration file, find the line that says <code>PermitRootLogin yes<\/code> and change it to:<\/sub><em><br><code>PermitRootLogin no<\/code><\/em><br><em><br><\/em>6. <strong>Save and Exit<\/strong>: In &#8216;nano&#8217;, you can save the changes by pressing <code>Ctrl+O<\/code>, then press <code>Enter<\/code>, and exit by pressing <code>Ctrl+X<\/code>.<br><br>7. <strong>Restart SSH Service<\/strong>: To apply the changes, restart the SSH service:<em><br><code>sudo systemctl restart ssh<\/code><\/em><\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"connecting-to-your-vpn\">Connecting to Your VPN<\/h3>\n\n\n<p>Import the downloaded .ovpn file into your OpenVPN client software.<br>Connect to the VPN using the provided credentials.<br>Visit <code>https:\/\/[your-configured-subdomain]<\/code> and log in using the provided credentials with the .ovpn file loaded in it.<\/p>\n\n\n\n<p>Please ensure all configurations and credentials are kept secure and confidential.<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-607c05b9 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Stop Juggling Servers, Start Scaling Your Business<\/h3><p class=\"uagb-cta__desc\">Tired of the AWS learning curve? Let Veeble&#8217;s experts handle the heavy lifting of managing your AWS infrastructure so you can focus on what matters most \u2013 growing your business.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/managed-aws-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">View Plans.<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve stumbled upon this guide, you\u2019re probably looking to enhance your organization\u2019s security by securing your production servers, just like I did a [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":8309,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9,5],"tags":[],"class_list":["post-1822","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-firewallsecurity","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/10\/Guide-to-Secure-Linux-Production-Servers-using-OpenVPN.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"If you\u2019ve stumbled upon this guide, you\u2019re probably looking to enhance your organization\u2019s security by securing your production servers, just like I did a [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=1822"}],"version-history":[{"count":31,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1822\/revisions"}],"predecessor-version":[{"id":8606,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1822\/revisions\/8606"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8309"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=1822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=1822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=1822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}