{"id":786,"date":"2022-10-20T20:41:36","date_gmt":"2022-10-20T20:41:36","guid":{"rendered":"http:\/\/wp.chaoyu.nl\/?p=786"},"modified":"2022-12-20T07:30:32","modified_gmt":"2022-12-20T07:30:32","slug":"ubuntu-x86-openvpn","status":"publish","type":"post","link":"https:\/\/chaoyu.nl\/?p=786","title":{"rendered":"Ubuntu 20.04 x86 openVPN"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Enable Root (ignore it, it is unsafe to use Root. I keep it to remind myself how wrong this is). Go directly to &#8220;<a href=\"#id_install_andConfig\" data-type=\"internal\" data-id=\"#id_install_andConfig\">Install VPN and Configure it<\/a> &#8220;<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">sudo passwd root<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">su root<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Enable root login over SSH<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">add line <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">PermitRootLogin yes<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save and exit the file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">systemctl restart sshd<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"id_install_andConfig\">Install VPN and Configure it <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">download this script as ubuntu user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">wget https:\/\/git.io\/vpn -O openvpn-install.sh<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Enable Key-phase Authentication<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">find the lines of creating SSL certificate in the script and remove \u201cnopass\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">$ grep -n '\"$client\" nopass' openvpn-install.sh\n241:\tEASYRSA_CERT_EXPIRE=3650 .\/easyrsa build-client-full \"$client\" nopass\n458:\t\t\tEASYRSA_CERT_EXPIRE=3650 .\/easyrsa build-client-full \"$client\" nopass<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use nano to open the .sh file and remove &#8220;nopass&#8221; from line 241 and 458. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Running openvpn-install.sh to install OpenVPN server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">chmod +x openvpn-install.sh   --makes it executable\nbash openvpn-install.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure you provide needed information<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">Welcome to this OpenVPN road warrior installer!\n\nWhich protocol should OpenVPN use?\n   1) UDP (recommended)\n   2) TCP\nProtocol [1]: 1\n\nWhat port should OpenVPN listen to?\nPort [1194]: \n\nSelect a DNS server for the clients:\n   1) Current system resolvers\n   2) Google\n   3) 1.1.1.1\n   4) OpenDNS\n   5) Quad9\n   6) AdGuard\nDNS server [1]: 2\n\nEnter a name for the first client:\nName [client]: anything\n\nOpenVPN installation is ready to begin.\nPress any key to continue...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">this will create a file on root home directory anything.ovpn. Copy it to ubuntu user home directory. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cp the .ovpn to \/home\/ubuntu\/ovpnusers <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">cd \nmkdir ovpnuser\nsudo cp \/root\/anything.ovpn \/home\/ubuntu\/ovpnuser<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Download .ovpn file onto your local machine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\"># logoff from ssh \nexit\n# execute this on your local machine. both windows or mac should work\n\nscp ubuntu@server_id:\/home\/ubuntu\/ovpnuser\/anything.ovpn .\n# this would download the anything.ovpn file to your current folder<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have the .ovpn file on your local machine, drag and drop it into your openvpn application. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start the connection and enter the key-phase. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OpenVPN Maintenance <\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Update to the newest Version<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">to check the openvpn version <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">openvpn --version<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Somehow, the openvpn is not in the ubuntu repo. At least not the newest version. But to stay secure, updated to the newest (stable) version is always a appreciated. Here is how.  And<a rel=\"noreferrer noopener\" href=\"https:\/\/community.openvpn.net\/openvpn\/wiki\/OpenvpnSoftwareRepos#DebianUbuntu:UsingOpenVPNaptrepositories\" data-type=\"URL\" data-id=\"https:\/\/community.openvpn.net\/openvpn\/wiki\/OpenvpnSoftwareRepos#DebianUbuntu:UsingOpenVPNaptrepositories\" target=\"_blank\"> here is official guide<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>add repo to vm<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">sudo -s\n\ncurl -fsSL https:\/\/swupdate.openvpn.net\/repos\/repo-public.gpg | gpg --dearmor &gt; \/etc\/apt\/trusted.gpg.d\/openvpn-repo-public.gpg\n\n\n# watch out here &lt;version&gt; &lt;osrelease&gt;\necho \"deb [arch=amd64 signed-by=\/etc\/apt\/trusted.gpg.d\/openvpn-repo-public.gpg] https:\/\/build.openvpn.net\/debian\/openvpn\/&lt;version&gt; &lt;osrelease&gt; main\" &gt; \/etc\/apt\/sources.list.d\/openvpn-aptrepo.list\n\n# I am running ubuntu 22.0.4, in my case I need \necho \"deb [arch=amd64 signed-by=\/etc\/apt\/trusted.gpg.d\/openvpn-repo-public.gpg] https:\/\/build.openvpn.net\/debian\/openvpn\/<strong>stable<\/strong> <strong>jammy<\/strong> main\" &gt; \/etc\/apt\/sources.list.d\/openvpn-aptrepo.list\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;version&gt; &lt;osrelease&gt; need to be substringed, <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Where&nbsp;<strong>&lt;version&gt;<\/strong>&nbsp;can be one of<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>stable<\/strong>: stable releases only &#8211; no alphas, betas or RCs<\/li>\n\n\n\n<li><strong>testing<\/strong>: latest releases, including alphas\/betas\/RCs<\/li>\n\n\n\n<li><strong>release\/2.3<\/strong>: OpenVPN 2.3 releases<\/li>\n\n\n\n<li><strong>release\/2.4<\/strong>: OpenVPN 2.4 releases, including alphas\/betas\/RCs<\/li>\n\n\n\n<li><strong>release\/2.5<\/strong>: OpenVPN 2.5 releases, including alphas\/betas\/RCs<\/li>\n\n\n\n<li><strong>release\/2.6<\/strong>: OpenVPN 2.6 releases, including alphas\/betas\/RCs<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">and&nbsp;<strong>&lt;osrelease&gt;<\/strong>&nbsp;depends your distribution:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>stretch<\/strong>&nbsp;(Debian 9.x)<\/li>\n\n\n\n<li><strong>buster<\/strong>&nbsp;(Debian 10.x)<\/li>\n\n\n\n<li><strong>bullseye<\/strong>&nbsp;(Debian 11.x)<\/li>\n\n\n\n<li><strong>xenial<\/strong>&nbsp;(Ubuntu 16.04 LTS)<\/li>\n\n\n\n<li><strong>bionic<\/strong>&nbsp;(Ubuntu 18.04 LTS)<\/li>\n\n\n\n<li><strong>focal<\/strong>&nbsp;(Ubuntu 20.04 LTS)<\/li>\n\n\n\n<li><strong>jammy<\/strong>&nbsp;(Ubuntu 22.04 LTS)<\/li>\n\n\n\n<li><strong>kinetic<\/strong>&nbsp;(Ubuntu 22.10)<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>sudo apt update<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">sudo apt update <\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>sudo apt upgrade<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">sudo apt upgrade<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Regular Admin tasks<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">--run \nbash openvpn-install.sh<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">-- outputs ----\nLooks like OpenVPN is already installed\n\nWhat do you want to do?\n   1) Add a cert for a new user\n   2) Revoke existing user cert\n   3) Remove OpenVPN\n   4) Exit\nSelect an option [1-4]: <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Final Step: Portforwarding<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">if you running this at home, like I am. The final step is going on to your router and under port forwarding, enable 1194 to your vpn server&#8217;s private ip address.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Enbale UFW to be sure \ud83d\ude42<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">sudo ufw enable \nsudo ufw allow 22 -- for ssh and sftp\nsudo ufw allow 1194 -- for openvpn \n\n# for ubuntu, no reload needed.<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Read Logs about All VPN collection<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">grep VPN \/var\/log\/syslog\n-- for me it is \ngrep chaoyuVPN \/var\/log\/syslog<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1582\" height=\"244\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2022\/12\/Screenshot-2022-12-19-at-21.56.57.png\" alt=\"\" class=\"wp-image-989\"\/><\/figure>\n\n\n\n<p class=\"has-black-color has-luminous-vivid-amber-background-color has-text-color has-background wp-block-paragraph\">Read more <a href=\"https:\/\/www.cyberciti.biz\/faq\/howto-setup-openvpn-server-on-ubuntu-linux-14-04-or-16-04-lts\/\" data-type=\"URL\" data-id=\"https:\/\/www.cyberciti.biz\/faq\/howto-setup-openvpn-server-on-ubuntu-linux-14-04-or-16-04-lts\/\" target=\"_blank\" rel=\"noreferrer noopener\">here!<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enable Root (ignore it, it is unsafe to use Root. I keep it to remind myself how wrong this is). Go directly to &#8220;Install VPN and Configure it &#8220; Enable root login over SSH add line Save and exit the file Install VPN and Configure it download this script as ubuntu user Enable Key-phase Authentication&#8230;<\/p>\n","protected":false},"author":1,"featured_media":794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[33,32],"class_list":["post-786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-openvpn","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=786"}],"version-history":[{"count":35,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":999,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions\/999"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/media\/794"}],"wp:attachment":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}