{"id":2200,"date":"2021-04-03T10:13:23","date_gmt":"2021-04-03T15:13:23","guid":{"rendered":"http:\/\/www.wildow.com\/blog\/?p=2200"},"modified":"2021-04-15T13:30:11","modified_gmt":"2021-04-15T18:30:11","slug":"reverse-vpn-turn-any-private-device-into-public-cloud-server-2","status":"publish","type":"post","link":"http:\/\/www.wildow.com\/blog\/?p=2200","title":{"rendered":"Reverse VPN: turn any private device into public cloud server"},"content":{"rendered":"<div class=\"page-header\">\n<h1><a href=\"https:\/\/coolaj86.com\/articles\/reverse-vpn-turn-any-private-device-into-public-cloud-server\/\">Reverse VPN: turn any private device into public cloud server<\/a><\/h1>\n<p><strong>Published<\/strong>\u00a0<span class=\"date\">2015-6-4<\/span>\u00a0<strong>Updated<\/strong>\u00a0<span class=\"updated\">01:44pm 2015-6-15<\/span><\/p>\n<\/div>\n<div class=\"row\">\n<div class=\"col-xs-10\">\n<p><strong>NOTICE<\/strong>\u00a0there might still be some bugs and sparsely commented snippets in this document, but if you follow it, it\u00a0<em>should<\/em>\u00a0work.<\/p>\n<p>Video Demo\u00a0<a href=\"https:\/\/youtu.be\/O7D7UkA3IKQ\">https:\/\/youtu.be\/O7D7UkA3IKQ<\/a>\u00a0by ravallblog<\/p>\n<p>Typically when you think of a VPN, you think of a private office network behind a firewall that you want to securely access from home or another office.<\/p>\n<p>But what about when your home server hosting your blog and your business site is stuck behind an apartment firewall?<\/p>\n<p>Or what if you want to be able to take a device with you, attach it to any network, and begin using it&#8217;s web services immediately?<\/p>\n<p>Effectively, we&#8217;re turning the VPN inside out. A reverse VPN, if you will.<\/p>\n<h2>Use a public VPS as the VPN server<\/h2>\n<p>Digital Ocean, ChunkHost, AWS, or a server (or Raspberry Pi) in your office, home, or a friend&#8217;s home &#8211; anything that you can get root access to and give a public network access (even if it&#8217;s with a dynamic dns service).<\/p>\n<p><strong>Install some tools<\/strong><\/p>\n<p><em>NOTE<\/em>: You\u00a0<em>must<\/em>\u00a0be using bash (the default shell \/ terminal) &#8212; not zsh or fish or anything fancy &#8212; legit\u00a0<em>bash<\/em>.<\/p>\n<p>Log into your VPS (<code>ssh user@example.com<\/code>) and then continue:<\/p>\n<h3>Install the Tools<\/h3>\n<pre><code class=\"language-bash hljs\">bash\r\nsudo apt-get install --yes openvpn\r\n<\/code><\/pre>\n<h3>Switch to the root user<\/h3>\n<p><strong>Be the root you know in your heart<\/strong>. You&#8217;re going to have to do pretty much everything as root from this point on, so it makes sense just to switch (if you aren&#8217;t root already).<\/p>\n<pre><code class=\"language-bash hljs\">sudo su -\r\n<\/code><\/pre>\n<h3>Get the easy-rsa 2.x tools from github<\/h3>\n<p>The new line of tools is 3.x, but I&#8217;m not familiar with those yet and these work, so these are what we will use. \ud83d\ude00<\/p>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-comment\"># Install git<\/span>\r\nsudo apt-get install --yes git\r\n<\/code><\/pre>\n<pre><code class=\"hljs bash\"><span class=\"hljs-comment\"># Copy all the files from the internet to your computer<\/span>\r\ngit <span class=\"hljs-built_in\">clone<\/span> https:\/\/github.com\/OpenVPN\/easy-rsa.git ~\/easy-rsa\r\n<span class=\"hljs-built_in\">pushd<\/span> ~\/easy-rsa\/\r\ngit checkout <span class=\"hljs-string\">'release\/2.x'<\/span>\r\n<span class=\"hljs-built_in\">popd<\/span>\r\n\r\n<span class=\"hljs-comment\"># Copy all the files into the right place<\/span>\r\nrsync -av ~\/easy-rsa\/easy-rsa\/2.0\/ \/etc\/openvpn\/easy-rsa\/\r\n<\/code><\/pre>\n<h3>Next we update the config<\/h3>\n<pre><code class=\"hljs bash\"><span class=\"hljs-comment\"># Push into the easy-rsa directory<\/span>\r\n<span class=\"hljs-built_in\">pushd<\/span> \/etc\/openvpn\/easy-rsa\/\r\n<\/code><\/pre>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-comment\"># Then open the .\/vars file, which is a config file<\/span>\r\n<span class=\"hljs-comment\"># You'll need to take a look around and season to taste<\/span>\r\n<span class=\"hljs-comment\"># It's nothing fancy, just names and preferences<\/span>\r\nvim .\/vars\r\n<\/code><\/pre>\n<p>Note a few things that you probably should change:<\/p>\n<p><code>\/etc\/openvpn\/easy-rsa\/vars<\/code>:<\/p>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-comment\"># change all of the things down at the bottom that look like these<\/span>\r\n<span class=\"hljs-comment\"># (these are given as an example for me, yours should be different)<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_COUNTRY=<span class=\"hljs-string\">\"US\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_PROVINCE=<span class=\"hljs-string\">\"Utah\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_CITY=<span class=\"hljs-string\">\"Provo\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_ORG=<span class=\"hljs-string\">\"AJ ONeal Tech LLC\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_EMAIL=<span class=\"hljs-string\">\"awesome@coolaj86.com\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_CN=<span class=\"hljs-string\">\"*.coolaj86.com\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_NAME=<span class=\"hljs-string\">\"AJ ONeal\"<\/span>\r\n<span class=\"hljs-built_in\">export<\/span> KEY_OU=<span class=\"hljs-string\">\"Department of Docs &amp; Blogging\"<\/span>\r\n<\/code><\/pre>\n<h3>Now we&#8217;ll get to work<\/h3>\n<p>Then load all of the vars into your environment<\/p>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-comment\"># load the variables<\/span>\r\n<span class=\"hljs-built_in\">source<\/span> .\/vars\r\n\r\n<span class=\"hljs-comment\"># delete any and all previous keys.<\/span>\r\n.\/clean-all\r\n\r\nmkdir -p .\/keys\r\nls -lah .\/keys\r\n\r\n<span class=\"hljs-comment\"># TODO (note to self) show the plain openssl commands (it's not that hard, y'know?)<\/span>\r\n\r\n<span class=\"hljs-comment\"># Build a certificate authority for your organization<\/span>\r\n.\/build-ca\r\n<span class=\"hljs-comment\"># <span class=\"hljs-doctag\">NOTE:<\/span> answer the questions<\/span>\r\n\r\nsudo apt-get install --yes tree\r\ntree .\/keys\/\r\n<span class=\"hljs-comment\"># The out put will look like this:<\/span>\r\n<span class=\"hljs-comment\"># .\/keys\/<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 ca.crt<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 ca.key<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 index.txt<\/span>\r\n<span class=\"hljs-comment\"># \u2514\u2500\u2500 serial<\/span>\r\n\r\n<span class=\"hljs-comment\"># Inpsect the keys, just for fun<\/span>\r\nopenssl x509 -text -noout -<span class=\"hljs-keyword\">in<\/span> .\/keys\/ca.crt\r\nopenssl x509 -text -noout -<span class=\"hljs-keyword\">in<\/span> .\/keys\/ca.key\r\n\r\n<span class=\"hljs-comment\"># When prompted, enter the same CN as above - coolaj86.com in my case<\/span>\r\n<span class=\"hljs-comment\"># No Password<\/span>\r\n.\/build-key-server rvpn.coolaj86.com\r\n\r\ntree .\/keys\/\r\n<span class=\"hljs-comment\"># .\/keys\/<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 01.pem<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 ca.crt<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 ca.key<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 index.txt<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 index.txt.attr<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 index.txt.old<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 rvpn.coolaj86.com.crt<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 rvpn.coolaj86.com.csr<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 rvpn.coolaj86.com.key<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 serial<\/span>\r\n<span class=\"hljs-comment\"># \u2514\u2500\u2500 serial.old<\/span>\r\n<\/code><\/pre>\n<pre><code class=\"hljs bash\"><span class=\"hljs-comment\"># The less you're doing with your computer, the longer this will take.<\/span>\r\n<span class=\"hljs-comment\"># If you're downloading a big file or something or https, it should only take a minute.<\/span>\r\n<span class=\"hljs-comment\"># Otherwise it could take several minutes<\/span>\r\n.\/build-dh\r\n<\/code><\/pre>\n<p>ProTipTM:<\/p>\n<p>If you use https, you can download a file over and over again (such as a large image) with curl and you&#8217;ll get a different set of bits each time because the random seed for the https connetion will be different. This will give you tons of entropy if you run it while generating keys.<\/p>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">true<\/span>; <span class=\"hljs-keyword\">do<\/span> sleep 1; curl <span class=\"hljs-string\">'https:\/\/pbs.twimg.com\/media\/A7hdDEnCYAA8oky.jpg:large'<\/span> &gt; \/dev\/null; <span class=\"hljs-keyword\">done<\/span>\r\n<\/code><\/pre>\n<pre><code class=\"language-bash hljs\">openvpn --genkey --secret keys\/ta.key\r\n<\/code><\/pre>\n<pre><code class=\"language-bash hljs\">curl -fssL https:\/\/gist.githubusercontent.com\/coolaj86\/18b92ee350b38f18fca6\/raw\/server.conf \\\r\n  -o \/etc\/openvpn\/server.conf\r\nvim \/etc\/openvpn\/server.conf \r\n<\/code><\/pre>\n<h3>Configure the Server&#8217;s Network and Firewall settings<\/h3>\n<pre><code class=\"language-bash hljs\">vim \/etc\/sysctl.conf\r\n<\/code><\/pre>\n<p><code>\/etc\/sysctl.conf<\/code>:<\/p>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-comment\"># uncomment the following<\/span>\r\nnet.ipv4.ip_forward=1\r\nnet.ipv6.conf.all.forwarding=1\r\n<\/code><\/pre>\n<p>TODO: the router may need to be setup to forward 1194 to the pi<\/p>\n<pre><code class=\"language-bash hljs\">sysctl -p\r\n\r\nufw status\r\nufw allow 1194\/udp\r\n\r\n<span class=\"hljs-comment\"># IMPORTANT change the 192.168.1.4 to your server's IP<\/span>\r\niptables -t nat -A POSTROUTING -s 10.8.0.0\/24 -o eth0 -j SNAT --to-source 192.168.1.4\r\n\r\ntouch \/etc\/firewall-openvpn-rules.sh\r\nchmod 700 \/etc\/firewall-openvpn-rules.sh\r\n\r\n<span class=\"hljs-comment\"># this will be open, you'll add the stuff below<\/span>\r\nvim \/etc\/firewall-openvpn-rules.sh\r\n<\/code><\/pre>\n<p><code>\/etc\/firewall-openvpn-rules.sh<\/code>:<\/p>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-meta\">#!\/bin\/bash<\/span>\r\n<span class=\"hljs-comment\"># IMPORTANT change the 192.168.1.4 to your server's IP<\/span>\r\niptables -t nat -A POSTROUTING -s 10.8.0.0\/24 -o eth0 -j SNAT --to-source 192.168.1.4\r\n<\/code><\/pre>\n<p>Now we&#8217;ll make sure that this firewall rule is added on each boot<\/p>\n<pre><code class=\"language-bash hljs\">vim \/etc\/network\/interfaces\r\n\r\n<span class=\"hljs-comment\"># You'll see a line that looks like this<\/span>\r\niface eth0 inet dhcp\r\n\r\n<span class=\"hljs-comment\"># underneath it you'll need to add this line<\/span>\r\n<span class=\"hljs-comment\"># (it shouldn't matter whether you use a tab or spaces)<\/span>\r\n        pre-up \/etc\/firewall-openvpn-rules.sh\r\n<\/code><\/pre>\n<p>And finally we&#8217;re ready to restart the openvpn service<\/p>\n<pre><code class=\"hljs sql\">\/etc\/init.d\/openvpn <span class=\"hljs-keyword\">stop<\/span>\r\n\/etc\/init.d\/openvpn <span class=\"hljs-keyword\">start<\/span>\r\n<\/code><\/pre>\n<h2>Use a private device as a Web Server<\/h2>\n<p>I must note that this\u00a0<em>should<\/em>\u00a0be the process:<\/p>\n<ul>\n<li>create your client key on the client,<\/li>\n<li>create a client.CSR.PEM (certificate signing request)<\/li>\n<li>send the client.CSR.PEM to the server<\/li>\n<li>the server creates a client.CRT.PEM from the client.CSR.PEM<\/li>\n<\/ul>\n<p>However, if the server is compromised then the server private key and certificate are compromised which means that every certificate the server has signed are now invalid.<\/p>\n<h3>On the SERVER<\/h3>\n<p>We&#8217;re going to create the client&#8217;s keys and OVPN file.<\/p>\n<pre><code class=\"hljs bash\"><span class=\"hljs-comment\"># For example<\/span>\r\n.\/build-key client-xyz.example.com\r\n<\/code><\/pre>\n<h4>Generating Client Keys<\/h4>\n<p>Each device will need its own keys.<\/p>\n<p>Use\u00a0<code>.\/build-key<\/code>\u00a0if the device is meant to be always-on and not require user interaction, like a raspberry pi home server.<\/p>\n<pre><code class=\"hljs properties\"><span class=\"hljs-comment\"># Example<\/span>\r\n<span class=\"hljs-comment\"># this will NOT require a passphrase<\/span>\r\n<span class=\"hljs-meta\">.\/build-key<\/span> <span class=\"hljs-string\">homeserver.coolaj86.com<\/span>\r\n<span class=\"hljs-comment\">\r\n# just showing the new files (omitting *.old backups)<\/span>\r\n<span class=\"hljs-attr\">tree<\/span> <span class=\"hljs-string\">.\/keys\/<\/span>\r\n<span class=\"hljs-comment\"># .\/keys\/<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 02.pem<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 homeserver.coolaj86.com.crt<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 homeserver.coolaj86.com.csr<\/span>\r\n<span class=\"hljs-comment\"># \u2514\u2500\u2500 homeserver.coolaj86.com.key<\/span>\r\n<\/code><\/pre>\n<p>Use\u00a0<code>.\/build-key-pass<\/code>\u00a0if the device is something you log into, such as your laptop.<\/p>\n<pre><code class=\"hljs properties\"><span class=\"hljs-comment\"># Example<\/span>\r\n<span class=\"hljs-comment\"># this WILL require a passphrase<\/span>\r\n<span class=\"hljs-meta\">.\/build-key-pass<\/span> <span class=\"hljs-string\">macbook.coolaj86.com<\/span>\r\n<span class=\"hljs-comment\">\r\n# just showing the new files (omitting *.old backups)<\/span>\r\n<span class=\"hljs-attr\">tree<\/span> <span class=\"hljs-string\">.\/keys\/<\/span>\r\n<span class=\"hljs-comment\"># .\/keys\/<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 03.pem<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 macbook.coolaj86.com.crt<\/span>\r\n<span class=\"hljs-comment\"># \u251c\u2500\u2500 macbook.coolaj86.com.csr<\/span>\r\n<span class=\"hljs-comment\"># \u2514\u2500\u2500 macbook.coolaj86.com.key<\/span>\r\n<\/code><\/pre>\n<p>Some devices (iOS, Android, Macbook(?)) need a des3 version of the key, might as well do that now:<\/p>\n<pre><code class=\"hljs vim\"># this will require your <span class=\"hljs-keyword\">previous<\/span> passphrase, <span class=\"hljs-built_in\">and<\/span> <span class=\"hljs-keyword\">to<\/span> create <span class=\"hljs-keyword\">a<\/span> passphrase (it can <span class=\"hljs-keyword\">be<\/span> the same)\r\nopenssl rsa -in .\/<span class=\"hljs-built_in\">keys<\/span>\/macbook.coolaj86.<span class=\"hljs-keyword\">com<\/span>.key -des3 -out .\/<span class=\"hljs-built_in\">keys<\/span>\/macbook.coolaj86.<span class=\"hljs-keyword\">com<\/span>.<span class=\"hljs-number\">3<\/span>des.key\r\n<\/code><\/pre>\n<pre><code class=\"language-bash hljs\">curl http:\/\/checkip.dyndns.org\r\ncurl https:\/\/coolaj86.com\/services\/whatsmyip\r\n\r\nvim \/etc\/openvpn\/easy-rsa\/keys\/Default.txt\r\n<\/code><\/pre>\n<p><code>\/etc\/openvpn\/easy-rsa\/keys\/Default.txt<\/code>:<\/p>\n<pre><code class=\"hljs properties\"><span class=\"hljs-attr\">client<\/span> \r\n<span class=\"hljs-attr\">dev<\/span> <span class=\"hljs-string\">tun <\/span>\r\n<span class=\"hljs-attr\">proto<\/span> <span class=\"hljs-string\">udp <\/span>\r\n<span class=\"hljs-attr\">remote<\/span> <span class=\"hljs-string\">coolaj86.com 1194 <\/span>\r\n<span class=\"hljs-meta\">resolv-retry<\/span> <span class=\"hljs-string\">infinite <\/span>\r\n<span class=\"hljs-attr\">nobind<\/span> \r\n<span class=\"hljs-meta\">persist-key<\/span> \r\n<span class=\"hljs-meta\">persist-tun<\/span> \r\n<span class=\"hljs-meta\">mute-replay-warnings<\/span> \r\n<span class=\"hljs-meta\">ns-cert-type<\/span> <span class=\"hljs-string\">server <\/span>\r\n<span class=\"hljs-meta\">key-direction<\/span> <span class=\"hljs-string\">1 <\/span>\r\n<span class=\"hljs-attr\">cipher<\/span> <span class=\"hljs-string\">AES-128-CBC <\/span>\r\n<span class=\"hljs-meta\">comp-lzo<\/span> \r\n<span class=\"hljs-attr\">verb<\/span> <span class=\"hljs-string\">1 <\/span>\r\n<span class=\"hljs-attr\">mute<\/span> <span class=\"hljs-string\">20 <\/span>\r\n<\/code><\/pre>\n<p><code>MakeOVPN.sh:<\/code><\/p>\n<pre><code class=\"hljs bash\"><span class=\"hljs-meta\">#!\/bin\/bash \r\n <\/span>\r\n<span class=\"hljs-comment\"># Default Variable Declarations <\/span>\r\nDEFAULT=<span class=\"hljs-string\">\"Default.txt\"<\/span> \r\nFILEEXT=<span class=\"hljs-string\">\".ovpn\"<\/span> \r\nCRT=<span class=\"hljs-string\">\".crt\"<\/span> \r\nKEY=<span class=\"hljs-string\">\".3des.key\"<\/span> \r\nCA=<span class=\"hljs-string\">\"ca.crt\"<\/span> \r\nTA=<span class=\"hljs-string\">\"ta.key\"<\/span> \r\nNAME=<span class=\"hljs-string\">\"<span class=\"hljs-variable\">${1}<\/span>\"<\/span>\r\n \r\n<span class=\"hljs-keyword\">if<\/span> [ -z <span class=\"hljs-string\">\"<span class=\"hljs-variable\">${NAME}<\/span>\"<\/span> ]; <span class=\"hljs-keyword\">then<\/span>\r\n  <span class=\"hljs-comment\">#Ask for a Client name <\/span>\r\n  <span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"Please enter an existing Client Name:\"<\/span>\r\n  <span class=\"hljs-built_in\">read<\/span> NAME \r\n<span class=\"hljs-keyword\">fi<\/span>\r\n \r\n \r\n<span class=\"hljs-comment\">#1st Verify that client\u2019s Public Key Exists <\/span>\r\n<span class=\"hljs-keyword\">if<\/span> [ ! -f <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$CRT<\/span> ]; <span class=\"hljs-keyword\">then<\/span> \r\n <span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"[ERROR]: Client Public Key Certificate not found: <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$CRT<\/span>\"<\/span> \r\n <span class=\"hljs-built_in\">exit<\/span> \r\n<span class=\"hljs-keyword\">fi<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"Client\u2019s cert found: <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$CR<\/span>\"<\/span> \r\n \r\n \r\n<span class=\"hljs-comment\">#Then, verify that there is a private key for that client <\/span>\r\n<span class=\"hljs-keyword\">if<\/span> [ ! -f <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$KEY<\/span> ]; <span class=\"hljs-keyword\">then<\/span> \r\n <span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"[ERROR]: Client 3des Private Key not found: <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$KEY<\/span>\"<\/span> \r\n <span class=\"hljs-built_in\">exit<\/span> \r\n<span class=\"hljs-keyword\">fi<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"Client\u2019s Private Key found: <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$KEY<\/span>\"<\/span>\r\n \r\n<span class=\"hljs-comment\">#Confirm the CA public key exists <\/span>\r\n<span class=\"hljs-keyword\">if<\/span> [ ! -f <span class=\"hljs-variable\">$CA<\/span> ]; <span class=\"hljs-keyword\">then<\/span> \r\n <span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"[ERROR]: CA Public Key not found: <span class=\"hljs-variable\">$CA<\/span>\"<\/span> \r\n <span class=\"hljs-built_in\">exit<\/span> \r\n<span class=\"hljs-keyword\">fi<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"CA public Key found: <span class=\"hljs-variable\">$CA<\/span>\"<\/span> \r\n \r\n<span class=\"hljs-comment\">#Confirm the tls-auth ta key file exists <\/span>\r\n<span class=\"hljs-keyword\">if<\/span> [ ! -f <span class=\"hljs-variable\">$TA<\/span> ]; <span class=\"hljs-keyword\">then<\/span> \r\n <span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"[ERROR]: tls-auth Key not found: <span class=\"hljs-variable\">$TA<\/span>\"<\/span> \r\n <span class=\"hljs-built_in\">exit<\/span> \r\n<span class=\"hljs-keyword\">fi<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"tls-auth Private Key found: <span class=\"hljs-variable\">$TA<\/span>\"<\/span> \r\n \r\n<span class=\"hljs-comment\">#Ready to make a new .opvn file - Start by populating with the default file <\/span>\r\ncat <span class=\"hljs-variable\">$DEFAULT<\/span> &gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n \r\n<span class=\"hljs-comment\">#Now, append the CA Public Cert <\/span>\r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;ca&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\ncat <span class=\"hljs-variable\">$CA<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;\/ca&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span>\r\n \r\n<span class=\"hljs-comment\">#Next append the client Public Cert <\/span>\r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;cert&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\ncat <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$CRT<\/span> | sed -ne <span class=\"hljs-string\">'\/-BEGIN CERTIFICATE-\/,\/-END CERTIFICATE-\/p'<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;\/cert&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n \r\n<span class=\"hljs-comment\">#Then, append the client Private Key <\/span>\r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;key&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\ncat <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$KEY<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;\/key&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n \r\n<span class=\"hljs-comment\">#Finally, append the TA Private Key <\/span>\r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;tls-auth&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\ncat <span class=\"hljs-variable\">$TA<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;\/tls-auth&gt;\"<\/span> &gt;&gt; <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> \r\n \r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"Done! <span class=\"hljs-variable\">$NAME<\/span><span class=\"hljs-variable\">$FILEEXT<\/span> Successfully Created.\"<\/span>\r\n \r\n<span class=\"hljs-comment\">#Script written by Eric Jodoin<\/span>\r\n<\/code><\/pre>\n<pre><code class=\"language-bash hljs\"><span class=\"hljs-built_in\">pushd<\/span> \/etc\/openvpn\/easy-rsa\/keys\r\n.\/MakeOVPN.sh client-xyz.example.com\r\n\r\n\r\n<span class=\"hljs-comment\"># copy this and paste it on the client<\/span>\r\ncat client-xyz.example.com.ovpn\r\n<\/code><\/pre>\n<h3>On the Client<\/h3>\n<p>You&#8217;ve just got to paste that config onto the client and start the connection.<\/p>\n<pre><code class=\"hljs dockerfile\">sudo apt-get install --yes openvpn\r\n<span class=\"hljs-comment\"># note it's important to use '&amp;' rather than ';' or '&amp;&amp;', even though it's a daemon<\/span>\r\nOVPN_CLIENT=<span class=\"hljs-string\">\"client-xyz\"<\/span>\r\nsudo kill --signal TERM $(cat \/var\/<span class=\"hljs-keyword\">run<\/span><span class=\"bash\">\/ovpn.<span class=\"hljs-string\">\"<span class=\"hljs-variable\">${OVPN_CLIENT}<\/span>\"<\/span>.pid)<\/span>\r\nsleep <span class=\"hljs-number\">0.5<\/span>\r\nsudo kill --signal KILL $(cat \/var\/<span class=\"hljs-keyword\">run<\/span><span class=\"bash\">\/ovpn.<span class=\"hljs-string\">\"<span class=\"hljs-variable\">${OVPN_CLIENT}<\/span>\"<\/span>.pid)<\/span>\r\nsudo openvpn --config <span class=\"hljs-string\">\"${OVPN_CLIENT}\"<\/span>.ovpn --daemon --writepid \/var\/<span class=\"hljs-keyword\">run<\/span><span class=\"bash\">\/ovpn.<span class=\"hljs-string\">\"<span class=\"hljs-variable\">${OVPN_CLIENT}<\/span>\"<\/span>.pid<\/span>\r\n<span class=\"hljs-comment\"># you can later kill the process with<\/span>\r\n<span class=\"hljs-comment\"># sudo bash -c 'kill $(cat \/var\/run\/client-xyz.pid)'<\/span>\r\n<\/code><\/pre>\n<p>Check if you were successful.<\/p>\n<pre><code class=\"hljs css\"><span class=\"hljs-selector-tag\">ifconfig<\/span>\r\n<span class=\"hljs-selector-tag\">ping<\/span> <span class=\"hljs-selector-tag\">-c<\/span> 1 10<span class=\"hljs-selector-class\">.8<\/span><span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.1<\/span>\r\n<\/code><\/pre>\n<p>If you were successful you&#8217;ll see a\u00a0<code>tun0<\/code>\u00a0device with an IP address and you should be able to ping the VPN server.<\/p>\n<h4>Connect on Startup<\/h4>\n<p>If you&#8217;re lucky the openvpn service was already configured to start on boot and all you have to do is move your config file to the correct directory and change the config file to say that it will be loaded<\/p>\n<pre><code class=\"hljs properties\"><span class=\"hljs-attr\">sudo<\/span> <span class=\"hljs-string\">mv client-xyz.example.com.ovpn \/etc\/openvpn\/client-xyz.conf<\/span>\r\n<span class=\"hljs-attr\">sudo<\/span> <span class=\"hljs-string\">vim \/etc\/default\/openvpn<\/span>\r\n<span class=\"hljs-comment\"># uncomment the following<\/span>\r\n<span class=\"hljs-comment\"># AUTOSTART=\"client-xyz\"<\/span>\r\n<\/code><\/pre>\n<p><strong>upstart<\/strong><\/p>\n<pre><code class=\"hljs properties\"><span class=\"hljs-attr\">vim<\/span> <span class=\"hljs-string\">\/etc\/init\/myopenvpn<\/span>\r\n<\/code><\/pre>\n<pre><code class=\"hljs vim\"># OpenVPN autostart <span class=\"hljs-keyword\">on<\/span> boot upstart job\r\n\r\nstart <span class=\"hljs-keyword\">on<\/span> runlevel [<span class=\"hljs-number\">2345<\/span>]\r\n<span class=\"hljs-keyword\">stop<\/span> <span class=\"hljs-keyword\">on<\/span> runlevel [!<span class=\"hljs-number\">2345<\/span>]\r\n\r\nrespawn\r\n\r\nexec \/usr\/sbin\/openvpn --status \/var\/run\/openvpn.client.status <span class=\"hljs-number\">10<\/span> --<span class=\"hljs-keyword\">cd<\/span> \/etc\/openvpn --config \/etc\/openvpn\/client.<span class=\"hljs-keyword\">conf<\/span> --syslog openvpn\r\n<\/code><\/pre>\n<p>By AJ ONeal<\/p>\n<div>\n<form class=\"js-contact-form\">If you loved this and want more like it, sign up!<\/p>\n<\/form>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Reverse VPN: turn any private device into public cloud server Published\u00a02015-6-4\u00a0Updated\u00a001:44pm 2015-6-15 NOTICE\u00a0there might still be some bugs and sparsely commented snippets in this document, but if you follow it, it\u00a0should\u00a0work. Video Demo\u00a0https:\/\/youtu.be\/O7D7UkA3IKQ\u00a0by ravallblog Typically when you think of a &#8230; <a class=\"more-link\" href=\"http:\/\/www.wildow.com\/blog\/?p=2200\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[],"class_list":["post-2200","post","type-post","status-publish","format-standard","hentry","category-vpn"],"_links":{"self":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2200"}],"version-history":[{"count":2,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2200\/revisions"}],"predecessor-version":[{"id":2202,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2200\/revisions\/2202"}],"wp:attachment":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}