{"id":43192,"date":"2022-10-07T16:44:21","date_gmt":"2022-10-07T16:44:21","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=43192"},"modified":"2024-12-15T15:39:54","modified_gmt":"2024-12-15T15:39:54","slug":"setup-openvpn-ubuntu-2204","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2022\/10\/setup-openvpn-ubuntu-2204\/","title":{"rendered":"How to Setup OpenVPN Server in Ubuntu 24.04 | 22.04 [The Easy Way]"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-43193\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This simple tutorial shows how to easily setup OpenVPN in your Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 24.04 server and connect remotely in Windows or Linux with GNOME.<\/p>\n<p>My PPTP and IKEv2 VPN server refused to work recently due to the Great Firewall (maybe). So I decided to setup OpenVPN in my Ubuntu VPS as a workaround.<\/p>\n<p>DigitalOcean has a step by step setup guide, but it&#8217;s really long and complicated for beginners. Thankfully, there&#8217;s a free open-source script make things as easy as few commands.<\/p>\n<h3>Step 1: Install OpenVPN<\/h3>\n<p>As mentioned, there&#8217;s a script in the <a href=\"https:\/\/github.com\/Nyr\/openvpn-install\" target=\"_blank\" rel=\"noopener\">github<\/a> to make things easy. It automatically detects your system, environment variable, IP address, and setup OpenVPN and firewall.<\/p>\n<p>The script is totally safe in my own opinion, and you can <a href=\"https:\/\/github.com\/Nyr\/openvpn-install\/blob\/master\/openvpn-install.sh\" target=\"_blank\" rel=\"noopener\">view the code<\/a> by yourself. Though, there&#8217;s always disclaimer that <b>use it as your own risk<\/b>!<\/p>\n<p><b>1.<\/b> First, connect to your Ubuntu\/Debian server either via SSH or other method that you favorite. Then grab the script by <code>wget<\/code>:<\/p>\n<pre>wget https:\/\/git.io\/vpn -O openvpn-install.sh<\/pre>\n<p><i>In case wget command does not exist, install via <code>sudo apt install wget<\/code>.<\/i><\/p>\n<p><b>2.<\/b> After downloaded the script, add executable permission via command:<\/p>\n<pre>chmod u+x openvpn-install.sh<\/pre>\n<p><b>3.<\/b> Finally, run the script:<\/p>\n<pre>sudo bash openvpn-install.sh<\/pre>\n<p>It will ask you a few questions to confirm IP address if your server is running behind NAT, choose UDP or TCP, set which port to listen to, and select a NDS server. <b>For lazy men, it&#8217;s OK hit Enter to use default for all previous questions.<\/b><\/p>\n<p>But, you need to finally type a name for the client. It will create a <b>.ovpn<\/b> file with the name you just typed.<\/p>\n<div id=\"attachment_43194\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-installer.webp\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-43194\" class=\"size-large wp-image-43194\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-installer-600x359.webp\" alt=\"\" width=\"600\" height=\"359\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-installer-600x359.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-installer-300x180.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-installer.webp 730w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-43194\" class=\"wp-caption-text\">Default options are usually OK except the client name<\/p><\/div>\n<p>After answering all the questions, hit any key to get start. It will do all the remained things, and generate a <b>.ovpn<\/b> file.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-done.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-43195\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-done-600x268.webp\" alt=\"\" width=\"600\" height=\"268\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-done-600x268.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-done-300x134.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/openvpn-done.webp 731w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>Step 2: Copy &amp; paste the .ovpn to client machine<\/h3>\n<p>As the screenshot above shows you, it generates the .opvn file in \/root directory in my case. In case you logged in via non-root user, copy the file to user&#8217;s home via:<\/p>\n<pre>sudo mv \/root\/*.ovpn ~\/ &amp;&amp; sudo chown $USER:$USER *.ovpn<\/pre>\n<p>Finally, you need to send the file to client machine, such as running the scp command below in your client PC (<b>run this command in client\/local machine<\/b>):<\/p>\n<pre>scp -P 22 username@server-ip:~\/*.ovpn .\/<\/pre>\n<p>Replace * with the filename, though it works if there no other .ovpn files. And, change port number 22 if non-default SSH listening port in use.<\/p>\n<h3>Step 3: Connect to OpenVPN server in Ubuntu\/Fedora<\/h3>\n<p>GNOME desktop has built-in client support for OpenVPN connection. Simply <b>open Gnome Control Center (aka Settings)<\/b> via the top-right corner system status menu.<\/p>\n<p>Then, go to &#8216;network&#8217; in left pane, and click on &#8216;+&#8217; after VPN section. Finally, click &#8216;Import from file&#8230;&#8217;<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/gnome-import-vpn.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-43196\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/gnome-import-vpn-600x375.webp\" alt=\"\" width=\"600\" height=\"375\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/gnome-import-vpn-600x375.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/gnome-import-vpn-300x188.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/gnome-import-vpn-768x480.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/gnome-import-vpn.webp 1020w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>In the pop-up file selection dialog, choose the <b>.ovpn<\/b> file you got from the server side. It will generate the VPN network automatically once you click open (<i>see the screenshot below<\/i>).<\/p>\n<div id=\"attachment_43197\" style=\"width: 592px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/auto-generate-openvpn.webp\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-43197\" class=\"size-large wp-image-43197\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/auto-generate-openvpn-582x600.webp\" alt=\"\" width=\"582\" height=\"600\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/auto-generate-openvpn-582x600.webp 582w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/auto-generate-openvpn-291x300.webp 291w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/auto-generate-openvpn.webp 632w\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" \/><\/a><p id=\"caption-attachment-43197\" class=\"wp-caption-text\">It automatically create the VPN network after selected the .ovpn file<\/p><\/div>\n<p>The default configurations are OK, though you may click editing advanced options as you need. After clicking on &#8216;Add&#8217; button, you can finally start connecting to the OpenVPN server either within Gnome Control Center or system status menu:<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-43198\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn-600x275.png\" alt=\"\" width=\"600\" height=\"275\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn-600x275.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn-300x138.png 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn-768x352.png 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn-1320x606.png 1320w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/10\/ubuntu-connectvpn.png 1347w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>Connect from Windows &amp; macOS:<\/h3>\n<p>OpenVPN website provides a client application for <a href=\"https:\/\/openvpn.net\/client-connect-vpn-for-windows\/\" target=\"_blank\" rel=\"noopener\">Windows<\/a> and <a href=\"https:\/\/openvpn.net\/client-connect-vpn-for-mac-os\/\" target=\"_blank\" rel=\"noopener\">macOS<\/a> users, simply download and install the app. Then, drop the .ovpn file into app window to create VPN connection.<\/p>","protected":false},"excerpt":{"rendered":"<p>This simple tutorial shows how to easily setup OpenVPN in your Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 24.04 server and connect remotely in Windows or Linux with GNOME. My PPTP and IKEv2 VPN server refused to work recently due to the Great Firewall (maybe). So I decided to setup OpenVPN in my Ubuntu VPS as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":43193,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2059],"class_list":["post-43192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-vpn"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/43192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=43192"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/43192\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/43193"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=43192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=43192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=43192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}