<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ren Jie Chong on Medium]]></title>
        <description><![CDATA[Stories by Ren Jie Chong on Medium]]></description>
        <link>https://medium.com/@renjiechong?source=rss-522554f64d58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0R4n7FTRoHp3KgRj9H7iWA.jpeg</url>
            <title>Stories by Ren Jie Chong on Medium</title>
            <link>https://medium.com/@renjiechong?source=rss-522554f64d58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:01:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@renjiechong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hacking with the Raspberry Pi Zero W]]></title>
            <link>https://levelup.gitconnected.com/hacking-with-the-raspberry-pi-zero-w-8520a4d72b2e?source=rss-522554f64d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/8520a4d72b2e</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Ren Jie Chong]]></dc:creator>
            <pubDate>Mon, 25 Jan 2021 02:11:51 GMT</pubDate>
            <atom:updated>2021-01-25T13:05:29.532Z</atom:updated>
            <content:encoded><![CDATA[<p>No internet connectivity… disabled Bluetooth &amp; WiFi… disabled external media storage… hard disk encryption… but that’s no reason why we can’t retrieve sensitive information from such machines! The exploit that I will be sharing is based on the following behavior:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Z5zJO8rnaluM48KO9lwyMQ.gif" /><figcaption>Image showing keyboard state being shared across all connected keyboards</figcaption></figure><p>See how toggling <em>Caps Lock</em> on one keyboard actually updates the state on the other keyboard — the same behavior is also observed for <em>Scroll Lock</em> and <em>Num Lock</em>. What this tells us, is that your OS keeps track of these keyboard states, and <strong>outputs</strong> them to all connected keyboard devices. Sorry for being Captain Obvious, but our usual interactions with the keyboard also tells us that it serves as an <strong>input</strong> device, firing characters into the OS.This means that as long as your target laptop/desktop has an open USB port that allows external keyboard connections, data can be taken out. To summarize, here’s what you will be needing:</p><ul><li>A target laptop that allows external keyboard connections via USB</li><li>A Raspberry Pi Zero W (~$15), with P4wnP1 A.L.O.A installed</li><li>Some patience to follow through on this post</li></ul><p>P4wnP1 A.L.O.A (A Little Offensive Appliance) provides you with an image that transforms your RPi Zero W into a handy pentesting / trolling device. It serves two vital functions, 1) Fooling the target machine into thinking that it is an external keyboard, and 2) Broadcasting a (hidden) WiFi hotspot / Bluetooth connection that allows you to control it when you are within range.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*hNRHSReehChBGzcnMTwcWA.png" /><figcaption>Diagram of RPi extracting information while acting as a keyboard</figcaption></figure><p>The above image shows a generic flow of how you will be able to trigger a sequence of keystrokes on the target machine, as well as to retrieve the desired information from it. To spice things up a little, this guide will help you through a POC that does the following:</p><ol><li>Inject a keylogger script into the target machine that prints keystrokes into a text file</li><li>Inject a second script that reads the text file, encodes it into a sequence of <em>Num</em>, <em>Scroll</em>, <em>Caps </em>key presses, which is then decoded by the RPi Zero W.</li></ol><p>Although P4wnP1 A.L.O.A works on Windows, OSX, and Linux, the scripts that we will be injecting into the target machine are Powershell scripts. You will need to adapt them to another language that you’re confident can be executed on your target machine (e.g. Python comes pre-installed in OSX and most popular Linux variants)</p><h3>Setting up P4wnP1 A.L.O.A</h3><ul><li>Download the latest image from the <a href="https://github.com/RoganDawes/P4wnP1_aloa/releases">official A.L.O.A GitHub release page</a></li><li>Flash the image into a microSD card using <a href="https://www.balena.io/etcher/">Balena Etcher</a></li><li>Slot the microSD card into your RPi Zero W. Ensure that the microUSB cable is connected to the second port, then plug it into the <em>target machine</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ukzLXM6k1nfbEhRXgq9b3A.jpeg" /><figcaption>Use this microUSB port for both power and data supply</figcaption></figure><ul><li>After 1–2 minutes, your RPi should start broadcasting a WiFi hotspot, which should look like the below picture. From the <em>Mastermind Machine</em>, connect to it using the password MaMe82-P4wnP1.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*HNsHKqXTQaKyutupTMR3pg.png" /><figcaption>SSID of the RPi hotspot</figcaption></figure><ul><li>Open your browser to http://172.24.0.1:8000, which provides you with a convenient GUI for changing any configurations. Take this chance to hide / modify the hotspot SSID.</li></ul><h3>Quick introduction to web GUI</h3><p>First, let’s take a look at the USB SETTINGS tab. To ensure that your RPi does not get blocked by the <em>Target Machine</em>, ensure that only the <em>Keyboard</em> functionality is enabled in bottom-right panel. You should also get your RPi to copy the product descriptions of the external keyboards that your <em>Target Machine</em> is expected to be used with. After all, you do not want to alarm users of the <em>Target Machine</em> when they see a notification saying that ‘<em>P4wnP1 by MaMe82</em>’ is ready for use 😅. A quick Google search returns the required information for <a href="https://devicehunt.com/search/type/usb/vendor/046D/device/any">Logitech USB Keyboards</a>. Once the relevant information has been updated, hit DEPLOY to effect the changes. To get these settings to run on startup, STORE it as a new profile, and set it as the default under the GENERIC SETTINGS tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3gLFW59ZJ7-sTGrAufOF3w.png" /><figcaption>USB Settings for P4wnP1 A.L.O.A</figcaption></figure><p>Next, we shall focus on the HIDSCRIPT tab, which is where we can configure the scripts to be run, as well as any results that are returned. Spend some time looking through the <a href="https://github.com/RoganDawes/P4wnP1_aloa">GitHub readme</a>, as well as the default scripts that are shipped with the A.L.O.A image by default — accessible via the LOAD &amp; REPLACE button. This allows you to quickly familiarize yourself with the standard functions that are available for you to use. Take note that while the HID scripts are to be written in JavaScript, methods such as setTimeout, setInterval, and even Promises, do not appear to be available for use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MEwjnt10ZrOV31dfA_cbgA.png" /><figcaption>HID Scripts for P4wnP1 A.L.O.A</figcaption></figure><p>Whenever a script runs to completion successfully, it will be appended to the ‘Succeeded’ section on the right panel. If your script has been written to return a result, you can view the details by click on the i tooltip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*LWQOVEkDIDxyZG3_TeHd5A.png" /><figcaption>Click on the ‘i’ tooltip to view script results</figcaption></figure><h3>Mapping characters to Num, Scroll, Caps Lock</h3><p>P4wnP1 terms the Num, Scroll, and Caps Lock buttons as a group of keys known as <em>LED keys</em>. As mentioned earlier, our aim is to transmit data from the <em>Target Machine</em> to the RPi by using the fact that LED key states can be output to keyboards. To accommodate for all 26 lowercase alphabets + the ‘space’ key, we can map each of them to a unique combination of 3 LED key presses (Since 3keys³ = 27keys).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*KIKljduwZ5GpQjz2ncdGWg.png" /><figcaption>Mapping for characters to LED key presses</figcaption></figure><p>Based on the A.L.O.A documentation, it is noted that in addition to <em>Num</em>, <em>Scroll</em> and <em>Caps Lock</em>, the waitLED() and waitAnyLED() functions return additional LED states for <em>Compose</em> and <em>Kana</em>. I have not tried using them, but it may be necessary to change the keyboard to use a Japanese layout in order for these 2 additional LED keys to work properly. If you do get them working, you could drastically increase the number of characters covered with just 3 keystrokes (5³ = 125).</p><h3>HID Script 1: Keylogger</h3><p>The following Powershell script (adapted from <a href="https://gist.github.com/dasgoll/7ca1c059dd3b3fbc7277">here</a>) logs the characters that the user inputs into a file on their Desktop, named testing-log.txt. For easier debugging purposes, testing-log.txt is opened once the keylogging has been cancelled with CTRL + C. Execute this in a Powershell terminal to validate that it works as expected.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8f5250bd8522b424e35c593ba27fc65/href">https://medium.com/media/b8f5250bd8522b424e35c593ba27fc65/href</a></iframe><p>Some additional work needs to be done, since the Powershell script is expected to be run on the <em>Target Machine</em>. Given our assumption that the <em>Target Machine</em> does not have any internet connectivity, we will need to get our RPi to open Powershell, and to type out the script one character at a time (Thankfully, this only takes ~3s). Take note how we collapsed the entire Powershell script into a single line (Line 11) in the HID script below. Do be wary of the need to escape special characters such as &quot; and \.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d4f322e267cc94ddd9f576401b45784/href">https://medium.com/media/1d4f322e267cc94ddd9f576401b45784/href</a></iframe><h3>HID Script 2: Read file &amp; fire LED keys</h3><p>Once you feel that the keylogger has certain information that you want, you can attempt to fetch it out using this second script. First and foremost, we will be relying on an injected Powershell script to read the testing-log.txt file and to translate each character into a series of LED key presses. At the same time, the HID script (JavaScript portion) must be ready to respond to each LED state change, and to map these changes back into its original character. Here’s the Powershell script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea8f16c4619a654d75b8b8329b3e01c4/href">https://medium.com/media/ea8f16c4619a654d75b8b8329b3e01c4/href</a></iframe><p>Ensure that on your Desktop, there is a testing-log.txt file with some content (keep it to just a-z and space characters). Then, run the above script in a Powershell terminal. Validate that the LED lights on your keyboard change as it encodes the log files’ contents and fires the LED key presses.</p><p>As usual, once you are satisfied with the result, we are ready to collapse the entire Powershell script into a single line, and to place it in a HID script. One important point to be careful about, is the delay that we have introduced into the Powershell script above in line 54. By allowing 3s before firing the LED key presses, we are allowing the JavaScript portion of the HID script to initialize properly. This ensures that when LED key presses are fired, the HID script is ready to translate them back into actual characters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b0cc428a3d9805a9caaa91d29d716e3/href">https://medium.com/media/1b0cc428a3d9805a9caaa91d29d716e3/href</a></iframe><h3>How to execute this?</h3><ol><li>If you only have a minute or two, attach the RPi to a USB port on the <em>Target Machine</em>. If it is a desktop and you have a bit more time, you can open the case, add a USB header to the motherboard and have your RPi hidden from plain sight.</li><li>Get to within a few meters of the Target Machine, and connect your mobile phone to the broadcasted hotspot.</li><li>Distract the user for a few seconds while you trigger HID Script #1 from your mobile phone (with hidePS() uncommented, and with a log file location that’s well hidden), which will start the keylogger.</li><li>Get the user to key in something sensitive… “Hey bro, i’m having difficulty logging into XYZ system. Are you facing the same issue?”</li><li>Distract the user again for a slightly longer period while you trigger HID Script #2. This encodes the data, fires LED key presses, then decodes them in your RPi.</li><li>Once the script has extracted the data, tap on the i tooltip to view the extracted content (e.g. in the image below, “apples are not pears”).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozRrgdondMGTUMu3qTpAjg.png" /><figcaption>viewing extracted information from the Target Machine</figcaption></figure><h3>Conclusion</h3><p>You’re not safe from this sort of data exfiltration for as long as your machine does not block its USB ports. In addition to the material shared here, your P4wnP1 A.L.O.A is capable of serving as a great tool to learn about pentesting in general, as it is build on top of Kali Linux. Do exercise caution while playing around with such tools though — there’s a fine line between learning about how to protect yourself better, versus trolling a close friend (ALT + F4 on their computer), versus something that is illegal / criminal.</p><p>As the scripts in this guide are written in Powershell, they are relevant only to Windows <em>Target Machines</em>. However, they can easily be adapted to another language that other OSes support. Furthermore, I would consider the current implementation to be flaky and incomplete. Additional work needs to be done to cover the full range of keyboard characters (mapping function enhancement), as well as to handle scenarios where the key presses occur so fast such that some information is lost (LED key press sequence that acts as delimiter?).</p><p>Whatever it is you are following this article for, I hope you’ve enjoyed it. Happy hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8520a4d72b2e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/hacking-with-the-raspberry-pi-zero-w-8520a4d72b2e">Hacking with the Raspberry Pi Zero W</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[U-been-tu Ubuntu?]]></title>
            <link>https://renjiechong.medium.com/u-been-tu-ubuntu-df556b778c1f?source=rss-522554f64d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/df556b778c1f</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[wsl]]></category>
            <category><![CDATA[windows-10]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Ren Jie Chong]]></dc:creator>
            <pubDate>Sun, 06 Dec 2020 14:40:54 GMT</pubDate>
            <atom:updated>2020-12-25T07:55:22.562Z</atom:updated>
            <content:encoded><![CDATA[<p>There are several great things that money can’t buy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SWMcqgputKwaIN7q" /><figcaption>Photo by <a href="https://unsplash.com/@beccatapert?utm_source=medium&amp;utm_medium=referral">Becca Tapert</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When I’m on the go, I carry my <a href="https://www.aftershockpc.com/welcome/Productinner/lunar-14-pro">Aftershock Lunar 14</a> with me. With WSL2, it meant a much more promising experience using Windows for regular surfing and light development. However, it’s been one year down the road, and I’ve never managed to get around the following issues:</p><ul><li><strong>Not all IDEs are compatible with WSL2</strong>: Integrated terminal experience with VS Code is great using the RemoteWSL extension, but the same can’t be said for IntelliJ IDEs.</li><li><strong>WSL2 projects have to be stored in the Linux file system</strong>: I initially made a symbolic link to my Windows file system for projects, but this made all read/write operations extremely sluggish. While this only affects WSL2 and not WSL, WSL2 offers a significant performance boost over WSL. Choose your trade-off…</li><li><strong>When plugged in, my laptop becomes a hairdryer</strong>: my laptop is fine when running on battery, but plugging in the power supply causes the fan to go berserk. This happens even after toggling all ‘<em>plugged in</em>’ power settings to match ‘<em>on battery</em>’ settings, and updating all drivers.</li></ul><p>This led me to rekindle my relationship with Ubuntu Desktop, an old flame that I had to forsake because my job responsibilities previously involved a ton of MS PowerPoint… and LibreOffice was always messing formatting up…</p><h3>Installing Ubuntu 20.04 LTS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y135zYQ_D83EWwtdR2VdjA.png" /><figcaption>Ubuntu 20.04 LTS — a beautifully designed, free OS. Faith in humanity restored.</figcaption></figure><p>The last time I used Ubuntu Desktop was with 16.04 LTS. It is refreshing to see that the official site no longer guilt trips you into making a donation before you download the image 😃. Here’s the general steps to get Ubuntu set up on your machine:</p><ol><li>Download the <a href="https://ubuntu.com/download/desktop">Ubuntu Desktop</a> image</li><li>Download and install<a href="https://www.balena.io/etcher/"> Balena Etcher</a></li><li>Use Etcher to flash the Ubuntu image to a thumb drive</li><li>With the thumb drive plugged in, restart your machine and boot into the Ubuntu image from the thumb drive (you may have to edit your BIOS settings first to prioritize booting into the thumb drive, or your machine may have a shortcut key that allows you to launch the boot menu)</li><li>Follow all the installation steps and you will have Ubuntu setup on your machine in no time.</li></ol><p>During one of the installation steps, you will be prompted if you would like to install Ubuntu alongside Windows (dual boot), or to perform a clean install of Ubuntu (no more windows).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dVMkfpH2lYKm2HDgaRrSoQ.jpeg" /><figcaption>Linux bootloader when more than 1 OS is available</figcaption></figure><p>Unsure if Ubuntu is for you? You can actually run Ubuntu directly from the thumb drive. Install whatever you need, poke around with the system, try using your laptop for what you purchased it for, then decide if Ubuntu is something you’d like to put a ring on.</p><p>If your answer is “I do”, I would strongly recommend doing a clean install of Ubuntu instead of dual booting — I got stung using it. One fine day Windows decided not to allow me to boot into it any longer. Deleting the Windows partition is not a trivial exercise, and perhaps due to my own incompetence, i corrupted my Linux bootloader (GRUB — GRand Unified Bootloader, which you see on bootup to decide if you want to load Windows / Ubuntu).</p><p>I shall never know if that ordeal was a result of a bad shutdown, a windows update incident etc that led to some corrupted data. One thing is for sure though, that I will never do a Windows + Linux dual boot again!</p><p>The unique thing about Linux is that it can be tailored to your heart’s desire. On the flip side, it may also require that some additional steps be taken to get certain things that you take for granted in Windows/OSX up and running. In the following sections, I will share the additional tools &amp; configurations that I performed — feel free to skip them if they are not relevant to you</p><h3>Can’t watch Netflix?!</h3><p>Netflix. The platform that tides one through these COVID-19 times. The horror that strikes you when your browser fails to stream it. The following was encountered with my Firefox browser. Some Googling may be necessary to resolve similar issues for another browser. Leave a comment if you require any help!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUFBuFfhviPNCJzQWJX2Bg.png" /><figcaption>A scene more frightening than any horror flick that ever existed</figcaption></figure><p>Thankfully, the fix is pretty straightforward and does not require any additional packages to be installed:</p><ol><li>Install ffmpeg via a terminal: sudo apt install ffmpeg</li><li>Open Firefox and go to about:addons in the address bar.</li><li>Click on Plugins on the left.</li><li>Follow the GIF below to ensure that OpenH264 Video Codec as well as Widevine Content Decryption Module are always enabled, and that they can be updated automatically.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AuxteOnDkSC0NxO9trv5fQ.gif" /><figcaption>Enabling Firefox plugins to get Netflix working</figcaption></figure><p>… and all is well again</p><h3>Optimizing power consumption / battery 🔋</h3><p>Once Ubuntu was setup, my laptop ran silent whether or not the power cable was plugged in — hairdryer problem solved! Regardless, I wanted to make sure that i configured my laptop to be as power efficient as possible. To get a good sense of the changes you’re effecting from each of these steps, you should run powerstat before and after each change. This would show you the power consumption (in watts) of your laptop.</p><p><strong>Dedicated NVIDIA driver</strong></p><p>My laptop comes with an NVIDIA graphics card. I installed the proprietary drivers for it via Software &amp; Updates &gt; Additional Drivers. After a reboot, open NVIDIA X Server Settings &gt; PRIME Profiles &gt; NVIDIA On-Demand and reboot again. Depending on your NVIDIA card model, changing this setting may result in significant power savings compared to keeping it in NVIDIA mode all the time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*htlC9hJEJ18Yr67C9s319Q.png" /><figcaption>Installing dedicated NVIDIA graphics cards</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*AB4gU9psoh3EhRDNz0ON-A.png" /><figcaption>Configuring graphics card to ‘On-Demand’</figcaption></figure><p><strong>Power profiles</strong></p><p>I wanted to ensure that I could still throttle things down even if the power supply was plugged in. Ubuntu does this using <strong>CPU governor profiles</strong>. By default, Ubuntu comes pre-configured with the profiles <strong>Performance</strong> and <strong>Powersave</strong>. Out of the box, you can view the available profiles, and set them manually via the following commands:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea9504502ae0efdf4be1709094fc355c/href">https://medium.com/media/ea9504502ae0efdf4be1709094fc355c/href</a></iframe><p>To be able to configure this easily, you can install indicator-cpufreq:</p><pre>$ sudo apt-get install indicator-cpufreq -y</pre><p>This will create an icon on the status bar that allows you to toggle across the available profiles</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*kov3qUTESxdNH3kDg4nqEg.png" /><figcaption>Toggle CPU governor profiles with indicator-cpufreq</figcaption></figure><h3>Customize with gnome-extensions</h3><p>I use Philips Hue lights at home and enjoy controlling it via my Windows desktops / laptops. On Ubuntu, this option is available via a gnome extensions. Gnome extensions allow you to customize your Ubuntu desktop experience. They are written in JavaScript and can be shared with others via the following <a href="https://extensions.gnome.org/">gnome shell extensions repository</a>. Most extensions will require the following to be installed to function properly:</p><pre>$ sudo apt-get install gnome-shell-extension-prefs -y</pre><p>While it is possible to download the zipped extensions, install, and enable them using gnome-extensions install PATH_TO_EXTENSION_ZIP, followed by gnome-extensions enable EXTENSION_NAME, it is infinitely easier to manage them directly from the repository. You can do this by clicking on the ‘<em>Click here to install browser extension’ </em>banner</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NtiXeS3DUWFMXMy6tcdUHQ.png" /><figcaption>Banner that indicates you have not installed the necessary gnome extension tool</figcaption></figure><p>Explore the repository to find what suits you best, and if you can’t find it, create your own! I’m personally using the following extensions:</p><ul><li>Hue Lights</li><li>OpenWeather</li><li>Sound Input &amp; Output Device Chooser</li><li>Status Area Horizontal Spacing</li></ul><p>Just take note that certain extensions may show an <em>ERROR</em> after installation. Don’t panic, just log out and log in again, and it may resolve itself (e.g. Status Area Horizontal Spacing extension)</p><h3>Binding additional mouse buttons</h3><p>Logitech has great support for Windows and OSX in allowing you to customize what your additional mouse buttons do. Good luck finding a similar GUI for Linux though… Thankfully we have xbindkeys, and with a little work, you can achieve customizations that you can’t get using the Windows / OSX GUI tools. First, install xbindkeys:</p><pre>$ sudo apt-get install xbindkeys xautomation -y</pre><p>Create a default config file from xbindkeys — this gives you some idea of what the configurations should look like:</p><pre>$ xbindkeys -d &gt; ~/.xbindkeysrc</pre><p>Next, we need to identify the IDs of your additional mouse buttons. Open a terminal, and run xev. The window that appears prints out logs for all keyboard and mouse events, including mouse cursor movements! So hold your mouse still within the window, and press the additional mouse buttons. Log messages similar to the following should be generated, indicating the mouse button IDs</p><pre>ButtonRelease event, serial 49, synthetic NO, window 0x5200001,<br>    root 0x5c3, subw 0x0, time 24671108, (341,325), root:(758,763),<br>    state 0x400, <strong>button 3</strong>, same_screen YES</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NX2MZxSguBBLSe48sFChBg.gif" /><figcaption>Mouse events being captured in xev</figcaption></figure><p>Now, we are ready to populate ~/.xbindkeysrc with the bindings we desire. Here is what i’m using (b:6 means button 6):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c44cc5a0c738fdb2633a35c850de5098/href">https://medium.com/media/c44cc5a0c738fdb2633a35c850de5098/href</a></iframe><p>Once these bindings have been added to ~/.xbindkeysrc, get xbindkeys to reload the updated configurations by running xbindkeys -p. If you get an error, it may be because xbindkeys is not running yet, in which case just need to execute xbindkeys. Your mouse bindings should now persist across restarts!</p><h3>Conclusion</h3><p>While I haven’t personally tried many of the FOSS Linux flavors, I dare say that in terms of features, UI, performance, most of them now pack a punch in the same weight class as their paid contenders. Compared to Windows, Linux operating systems tend to be a lot more lightweight (not referring to their figurative weight class!), which is why they are a spectacular choice for reviving machines that belong in the museum.</p><p>Depending on your hardware, you may be required to put in some legwork before things run smoothly. However, the strong community support that these platforms receive today, no longer makes it prohibitive for you to get over this initial hurdle. In a nutshell, its free, relatively easy to set up, and can be customized far more easily than Windows / OSX… so what more do you need?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df556b778c1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unleash the potential of your unrooted Android phone]]></title>
            <link>https://levelup.gitconnected.com/unleash-the-potential-of-your-unrooted-android-phone-ae835c4af633?source=rss-522554f64d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae835c4af633</guid>
            <category><![CDATA[termux]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Ren Jie Chong]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 13:58:23 GMT</pubDate>
            <atom:updated>2020-10-13T12:46:18.348Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tV9I-KdiE0xwheTf" /><figcaption>Photo by <a href="https://unsplash.com/@geekyshots?utm_source=medium&amp;utm_medium=referral">Geeky Shots</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>An estimated <a href="https://www.idc.com/promo/smartphone-market-share/os">85% of smartphone users</a> worldwide use Android. Regardless of whether you were drawn to the ecosystem for its affordable price point, highly customizable nature, or your outright contempt of fruit, there is a very good chance that you have not explored the amazing things your (unrooted) Android device can do.</p><p>At its core, the Android OS is built on top of a Linux kernel. One of the main differences between Android and other distros is that it does not come packaged with many of the GNU libraries commonly found in Linux. As a result, most applications cannot be run in Android. Instead, the Android Runtime (ART) executes dex files and bytecode that has been compiled from Java — apps from the play store that we’re all too familiar with.</p><p>Figuring out a convenient way to access the Linux shell is key to unleashing your phone’s potential. Thankfully, the doors to the terminal have been kept pretty open, and today, we can build upon the fantastic contributions that have been made to various open-sourced projects… enter Termux.</p><h3>Installing Termux</h3><blockquote>Termux is an <strong>Android terminal emulator</strong> and Linux environment application that works directly with no rooting or setup required. A <strong>minimal base system</strong> is installed automatically, additional packages are available using the package manager.</blockquote><p>That is how the <a href="https://wiki.termux.com/wiki/Main_Page">official documentation</a> defines this nifty tool. The experience Termux gives is similar to what you get when creating docker images from an Alpine base image —a minimal, lightweight environment. After installing Termux from the <a href="https://play.google.com/store/apps/details?id=com.termux">play store</a>, follow these simple steps to make it work harder for you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef81c6c2a1e17555cdcd44db7b1cbfd5/href">https://medium.com/media/ef81c6c2a1e17555cdcd44db7b1cbfd5/href</a></iframe><p>Do take note that there are limitations as to what you can install in Termux. For example, my attempts at getting nvm working never succeeded (<a href="https://github.com/nvm-sh/nvm/issues/1645">thread here</a>), which is why i rely on the nodejs-lts package instead. Installing dependencies can be a bit of a hit and miss, but at least in my experience, you can get most things up and running with a little tweaking.</p><p>In this day and age, you would be forgiven for thinking Termux bland. After all, here is a terminal that doesn’t shimmer with fancy colors, and it does not appear to augment the individual with 1337-developer abilities. Let’s fix that next!</p><h3>Installing Oh-My-Termux</h3><p>If you develop from a Linux or OSX machine, you’re likely to have used or seen someone use Oh-My-Zsh at some point. At the heart of it all lies Zsh, which is pretty much like Bash, but with added capabilities such as built-in customization via plugins and themes (look <a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Themes">here</a> for the list of official themes). To get things working with the least amount of effort, I would recommend setting up Oh-My-Termux. It sets you up with the most popular theme, <a href="https://github.com/Powerlevel9k/powerlevel9k">Powerlevel9k</a>, and installs the necessary Powerline font for you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f58abbf967ebb9453bb344d3ec4e7ba/href">https://medium.com/media/3f58abbf967ebb9453bb344d3ec4e7ba/href</a></iframe><p>To toggle your shell between Bash or Zsh, you can type chsh followed by bash or zsh respectively, then restart your shell. Here’s a comparison of the uninspiring default Bash shell against Zsh after installing Oh-My-Termux. In Bash, I have to type the full git command that I want to execute. With Oh-My Termux, however, I just need to type git a and hit the TAB key, which provides me with a list of matching git commands that I can use. Here’s what they look like before and after the facelift:</p><figure><img alt="(Left) Image of plain Bash terminal versus (Right) a Zsh terminal with lots of useful information" src="https://cdn-images-1.medium.com/max/1024/1*r8JorRPR6oqyFAKT968fNg.jpeg" /><figcaption>(Left) Image of plain Bash terminal versus (Right) a Zsh terminal with lots of useful information</figcaption></figure><p>With Bash, anything that we want to initialize (such as scripts or environment variables) whenever we open a shell is typically added to ~/.bashrc. For Zsh, the same concept applies, but we’re now looking at ~/.zshrc. This is also where Zsh can be customized to your desires:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ac3c39842bf3f951f41780aba7cc486/href">https://medium.com/media/8ac3c39842bf3f951f41780aba7cc486/href</a></iframe><p>Note that Powerlevel9k is deprecated at the time of this writing. You may wish to update your configurations to use its successor, <a href="https://github.com/romkatv/powerlevel10k">Powerlevel10k</a>. It offers some material and aesthetic enhancements, such as having plugins load in a non-blocking manner, as well as a new CLI wizard for customizing the interface further.</p><h3>So what can we do now?</h3><p>Having Termux and Oh-My-Termux setup with NodeJS theoretically allows you to take on web development tasks… but that’s a little hardcore if you ask me. I will not last more than 15 minutes staring at a 6&quot; screen; and mashing away at the soft keyboard with my fat fingers will simply accelerate the degradation of my screen around the BACKSPACE key. But hey, perhaps tunnel vision is your special ability, or you’re one of those Vim gurus, in which case, go for it! If not for full-fledged development, what then do I use Termux for?</p><ul><li><strong>Using it to control my Heroku services</strong>: upgrading projects to the Hobby tier when I need them to be up more reliably, then switching them back to the Free tier &amp; scaling the web dynos to 0 when I want them hidden. The easiest way to get Heroku on Termux is via npm i -g heroku. With the following script placed in ~/toggleHeroku.sh, we can start or stop our services using ~/toggleHeroku.sh start or ~/toggleHeroku.sh stop.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/691857c036a05f13d71e1c6f9de6e902/href">https://medium.com/media/691857c036a05f13d71e1c6f9de6e902/href</a></iframe><ul><li><strong>Running a mock server for mobile apps</strong>: When developing mobile apps, it’s a good idea to have a backend that can serve mocks responses to the app. This allows frontend developers to focus on the client UI and logic, instead of having to worry about server readiness or network instability. What better way to do this than by having the mock server running on the very same phone?</li><li><strong>Getting opinions about a WIP project</strong>: If you have a project that is still very much a work-in-progress or contains sensitive information, controlling its distribution is going to be one of your top priorities. But what if you need the opinion of another, but do not wish to lug your laptop around? One way that works for me is by cloning the project into Termux, running it, then viewing it from my phone’s browser. To convince yourself that this works, try it out with a create-react-app project:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/361f5ac64a05dab66a0bc700e5dceef6/href">https://medium.com/media/361f5ac64a05dab66a0bc700e5dceef6/href</a></iframe><p>If you’re on a tablet the bigger screen size offers more options for you to create a sensible developer experience. You could use Android’s split screen feature for Termux and your browser, and you could even install Tmux to create multiple sessions in the same Termux screen. But just to prove that features such as Hot Module Reloading would still work…</p><figure><img alt="Hot module reloading for a create-react-app project using Termux and Firefox" src="https://cdn-images-1.medium.com/max/600/1*l9Tnqgqy5R965cVUOqIpHw.gif" /><figcaption>Hot module reloading for a create-react-app project using Termux and Firefox</figcaption></figure><h3>Going one step further with AnLinux</h3><p>Whatever we have achieved so far allows you to see how your web projects behave on a mobile phone. To some extent, you could also test how things would render on a desktop if you use a browser that offers toggling to Desktop site (e.g. Firefox, Chrome). This doesn’t always work though, and mouse-related events such as :hover will simply not be testable.</p><p>If having this capability is important to you, you will be glad to hear what AnLinux has to offer. AnLinux can be downloaded from the <a href="https://play.google.com/store/apps/details?id=exa.lnx.a&amp;hl=en_IN">play store here</a>. As the app’s full name suggests, it basically allows you to <em>Run Linux On Android Without Root Access</em>. Under the hood, it makes use of <a href="https://wiki.termux.com/wiki/PRoot">PRoot</a>, which is:</p><blockquote>… a user-space implementation of chroot, mount --bind, and binfmt_misc. This means that users don’t need any privileges or setup to do things like using an arbitrary directory as the new root filesystem, making files accessible somewhere else in the filesystem hierarchy, or executing programs built for another CPU architecture transparently through QEMU user-mode.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VggyzlzatAYZ9QWsWDlM5g.jpeg" /><figcaption>(Left) Features in AnLinux menu that we will use, (Middle) Installation of a Linux distro and (Right) setup of a desktop GUI.</figcaption></figure><p>For this guide, we will be going through the setup of a Linux distro (unintuitively termed Dashboard in the image above), followed by installation of a Desktop Environment. Why 2 steps? Installing a distro server grants you a shell environment, which allows you to do sysadmin related operations. Optionally, and in our case, we wish to have a GUI to analyze how our apps respond on a Desktop. Hence we need to install a desktop environment too.</p><p><strong>1Install Linux distro (Dashboard)</strong>: I’ve only tried using Ubuntu so far, and would strongly recommend you use it as your primary distro. Copy the command from AnLinux and execute it in Termux — this should only take a minute or two. Once installation is complete, you will see a file created in ~/start-ubuntu.sh.</p><p><strong>2Install Desktop Environment</strong>: I strongly recommend Xfce4, because when i attempted Mate, LXQt, or LXDE, the Desktop environments did not render properly. First, ensure that you execute ~/start-ubuntu.sh, which activates the Ubuntu instance in your shell. You can identify that you’re in the Ubuntu shell by observing how your beautiful Oh-My-Termux interface is now gone (you can always set it up for the Ubuntu instance later). Execute the command copied over from AnLinux. Go for coffee — the installation took approximately <strong>23 minutes</strong> before I was prompted to select my keyboard layout. It continued running for another 15<strong> minute</strong>s before prompting me to set a VNC password, then was finally completed.</p><p>At this point, the Ubuntu instance would have been installed with a TigerVNC server. Several VNC commands are now symbolically linked to your bin folder:</p><ul><li><strong>vncpasswd</strong>: execute this to change your VNC password.</li><li><strong>vncserver-stop</strong>: shuts down the VNC server. By default, it will run vncserver -kill :1, preventing further connections to display 1.</li><li><strong>vncserver-start</strong>: starts the VNC server. By default, it will run vncserver -geometry 1028x768 -depth 24 -name remote-desktop :1, permitting client connections to display 1 via port 5901. Note how the server gets run with a resolution of 1028x768. To modify this to suit your client’s screen resolution, we need to modify the <strong>vncserver-start</strong> script:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/969040061685c1048585db32f934f59e/href">https://medium.com/media/969040061685c1048585db32f934f59e/href</a></iframe><p>Restart the VNC server by running vncserver-stop, followed by vncserver-start.</p><h3>Connect with a VNC Viewer</h3><p>All that remains is to connect a client to view the Ubuntu Xfce4 GUI. You can make the connection from a desktop or laptop using a client such as RealVNC over http://[phone-lan-ip]:5901. However, given that we went through these additional steps to see the GUI from our phone, download <a href="https://play.google.com/store/apps/details?id=com.realvnc.viewer.android">RealVNC</a> from the play store, and make a connection to 127.0.01:5901. Input your VNC password when prompted — You should now be able to interact with your desktop GUI!</p><p>For some reason, the internet browser did not work for me until I installed Firefox by opening a terminal and executing apt install firefox. Feel free to install chrome or any other browser based on your preferences/needs.</p><figure><img alt="Image of VNC viewer from Android phone, connected to TigerVNC server of Termux’s Ubuntu instance in the same phone." src="https://cdn-images-1.medium.com/max/1024/1*dhkVQaMSKGDFgwR-gKzG-g.jpeg" /><figcaption>Image of VNC viewer from Android phone, connected to TigerVNC server of Termux’s Ubuntu instance in the same phone.</figcaption></figure><h3>Conclusion</h3><p>We have explored how Termux, Oh-My-Termux, and AnLinux complement each other to turn your Android phone into a development machine. As you attempt to install the dependencies you need, you’re likely to encounter the occasional bump in the road due to how Termux was designed; pseudo-root access from PRoot; or lack of support for ARM architectures. Nevertheless, It allows us to do so much more with our phones, where the limitations are less because of technical challenges, but more from our lack of imagination.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae835c4af633" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/unleash-the-potential-of-your-unrooted-android-phone-ae835c4af633">Unleash the potential of your unrooted Android phone</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you fail2ban unauthorized server access?]]></title>
            <link>https://medium.com/swlh/do-you-fail2ban-unauthorized-server-access-59887fd7884d?source=rss-522554f64d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/59887fd7884d</guid>
            <category><![CDATA[fail2ban]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[bots]]></category>
            <dc:creator><![CDATA[Ren Jie Chong]]></dc:creator>
            <pubDate>Tue, 06 Oct 2020 05:14:00 GMT</pubDate>
            <atom:updated>2020-10-06T05:14:00.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OAq_HvUbzE-24QlZ" /><figcaption>Photo by <a href="https://unsplash.com/@cbpsc1?utm_source=medium&amp;utm_medium=referral">Clint Patterson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When most of us think of a hacker, we imagine a sinister figure from the underworld who lives in perpetual darkness, whose only comprehension of light is of the panel from his screen. The keyboard — an extension of his limbs — does his bidding with each and every rapid, purposeful keystroke. Nothing stands in the way of his unparalleled wit, as he lays waste to the layers of security meant to keep him out. He grins and lets out a sigh of satisfaction, tapping the Enter key one final time, then leans back in his chair for a well-earned respite. He has gained unauthorized entry into a server, and with it, the troves of valuable data that it holds.</p><p>Hollywood has sensationalized our notion of the hacker, portraying their actions as highly manual yet effective, and directed towards entities that are of value. “ I’m not holding any information that is of value, no one would want to hack my systems… right?” Wrong! One thing we can be certain of is that the process of uncovering vulnerabilities to exploit requires tedious trial and error, far from the glorious imagery depicted by movies.</p><p>Most attacks today are executed by bots, methodically scouring IP addresses in the web, making attempts to identify the ports and systems that are in use, and establishing the attack surface. According to <a href="https://cheatsheetseries.owasp.org/cheatsheets/Attack_Surface_Analysis_Cheat_Sheet.html">OWASP</a>, the attack surface is:</p><ol><li>the sum of all paths for data/commands into and out of the application</li><li>the code that protects these paths (including resource connection and authentication, authorization, activity logging, data validation and encoding)</li><li>all valuable data used in the application, including secrets and keys, intellectual property, critical business data, personal data and PII</li><li>the code that protects these data (including encryption and checksums, access auditing, and data integrity and operational security controls).</li></ol><p>Each vector in the attack surface represents a potential doorway for a hacker to enter. All that a hacker needs to do, is persist in his search for a door that hasn’t been locked properly.</p><h3>What is fail2ban?</h3><p>In a nutshell, fail2ban prevents brute force attacks on your server. It can be configured to identify suspicious connections, and to jail (fail2ban lingo for ban) the originating IP address when transgressions exceed a defined limit. What this does is make it significantly harder for a hacker to establish the attack surface and consequently, perform targeted attacks.</p><p>I have configured my SSH server to jail IP addresses for 1 week if there are 3 failed or invalid attempts within 72 hours. To give you a sense of how prevalent these attacks are, take a look at my current SSH jail status:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/266415a65c4c7a8b5b4b75e15b905aa6/href">https://medium.com/media/266415a65c4c7a8b5b4b75e15b905aa6/href</a></iframe><p>Every single day, I get at least 15 unique IP addresses prodding at my server. To get some sense about where these attacks are coming from, we can run the following code to read the fail2ban logs and map each offending IP addresses to a country:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cec54cdc702da7ecace271c5c67d464/href">https://medium.com/media/5cec54cdc702da7ecace271c5c67d464/href</a></iframe><p>Now, are you convinced that fail2ban is worth your while?</p><h3>Installing fail2ban</h3><p><strong><em>Note</em></strong><em>: Installing fail2ban is easy. Unfortunately it is equally easy to lock yourself out of your server while you are in the midst of configuring it properly. I strongly recommended that you proceed with the following steps when you have physical access to the server. If that is not possible, at least make sure that you have enough time to set it up properly with your trusted IP addresses whitelisted.</em></p><p>When you’re comfortable to begin, here’s how to install fail2ban:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8c3e3c9957de41598cfea10269518cb/href">https://medium.com/media/e8c3e3c9957de41598cfea10269518cb/href</a></iframe><h3>Understanding the configuration files</h3><p>fail2ban installs configuration files to /etc/fail2ban. Let’s take a look at the important components of this folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86bf7ef57c17ef74459ced2a9b65754a/href">https://medium.com/media/86bf7ef57c17ef74459ced2a9b65754a/href</a></iframe><ul><li><strong>fail2ban.conf</strong> and <strong>fail2ban.local</strong>: These files determine the general settings of fail2ban — where log files are kept, the level of information to log. The convention is to leave fail2ban.conf as it is, but to copy it to fail2ban.local and modify the settings there.</li><li><strong>jail.conf</strong> and <strong>jail.local</strong>: These files contain the configurations for each jail — which logs to read; the number of failed attempts before an IP is jailed etc. Similarly, we typically make a copy of jail.conf to jail.local and make modifications there.</li><li><strong>filter.d</strong>: This folder contains the regex patterns that we would like each service to register as a failed attempt.</li><li><strong>action.d</strong>: This folder contains the list of actions that we can perform when an IP address gets jailed by a service. The most common one that you will use is iptables-allports.conf, as it allows us to block an IP address across all ports.</li><li><strong>jail.d</strong>: For services that do not have jail configurations setup in jail.local, you can define a new file in this folder like I did for Gitea.</li><li><strong>paths-common.conf</strong>: Contains environment variables used by the config files of various services, such as paths to system logs.</li></ul><h3>Whitelisting trusted IP addresses</h3><p>Locking yourself out of the server is possible while you are tinkering with the regex patterns to use in filter.d. Unfortunately for myself, I’ve been there and done that… twice. To prevent this from happening, you can whitelist the trusted IP addresses which you connect from in /etc/fail2ban/jail.local. This would allow your IP address to violate any of the filter.d regex patterns without getting banned.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e670d7a90e05d9d3ea6c387b1d58d7dc/href">https://medium.com/media/e670d7a90e05d9d3ea6c387b1d58d7dc/href</a></iframe><p>IP ranges can be conveniently whitelisted using CIDR (Classless Inter-Domain Routing). You may use <a href="https://www.ipaddressguide.com/cidr">this tool</a> to help convert between an IP range and CIDR. By default, the loopback IPv4 block 127.0.0.1/8 and IPv6 ::1 addresses are ignored. In addition to these, I have added 192.168.1.0/24 to whitelist all devices in my LAN. Do make sure that additions are space-delimited.</p><h3>Enabling SSHD jail</h3><p>We need to add in a block of code into /etc/fail2ban/jail.local to enable the SSHD jail with the desired configurations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9e4fa8c424577bb0c59fc7d5ebef5be/href">https://medium.com/media/e9e4fa8c424577bb0c59fc7d5ebef5be/href</a></iframe><ul><li><strong>enabled</strong>: true / false. Enough said.</li><li><strong>mode</strong>: normal, ddos, extra, aggressive. Take a look at /etc/fail2ban/filter.d/sshd.conf to see the additional regex matchers that get added as we opt for a stricter setting (cmnfailre, mdre-ddos, mdre-aggressive).</li><li><strong>port</strong>: keep it as ssh if you are using the default port 22 for your ssh server. Otherwise, change it accordingly.</li><li><strong>logpath</strong>: specifies log path for SSH authentication attempts. This variable is defined in paths-common.conf and points to /var/log/auth.log by default.</li><li><strong>backend</strong>: specifies how log files will be monitored; auto, pyinotify, gamin, polling…</li><li><strong>maxretry</strong>: failed attempts before a jail is activated.</li><li><strong>bantime</strong>: how long to keep an IP address in a jail.</li><li><strong>findtime</strong>: how far back to search for failed attempts.</li></ul><p>Personally, i feel that even the aggressive mode of filters are too lenient on these bots. By occasionally browsing through the SSHD attempts in /var/log/auth.log, I have identified several more logs that i wanted to mark as a failed attempt. The corresponding regex patterns for the logs can be appended to /etc/fail2ban/filter.d/sshd.conf:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/868ccd75c8bb76dcf81fd0a00d54885f/href">https://medium.com/media/868ccd75c8bb76dcf81fd0a00d54885f/href</a></iframe><p>To update fail2ban with the new configurations, run:</p><pre>$ sudo fail2ban-client reload</pre><p>Next, leave your server running for a few hours, then come back to check the status of your SSHD jail!</p><pre>$ sudo fail2ban-client status sshd</pre><h3>Testing regex patterns</h3><p>Before adding new regex patterns, I would recommend temporarily increasing maxretry to prevent accidental lockouts. We can then make use of fail2ban-regex to validate if a regex pattern matches any of the log entries that we are trying to detect:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c454beddc2c5a8ec0e7053a04d872d7d/href">https://medium.com/media/c454beddc2c5a8ec0e7053a04d872d7d/href</a></iframe><p>It takes time to build trust with a new tool, so if you are feeling a little skeptical about the output of fail2ban-regex, that’s completely understandable. To allay your worries, you can do a very rough test by grep’ing the output of the log file. In my case, the following returns the same IP addresses as fail2ban-regex:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/457c71edeff704893b2207816fb53b02/href">https://medium.com/media/457c71edeff704893b2207816fb53b02/href</a></iframe><p>Once you’re happy with the results, remember to reload your configurations with sudo fail2ban-client reload. Once the new patterns have been applied, it is always prudent to perform a valid authentication, and check that it does not get categorized as a failed attempt via fail2ban-regex.</p><h3>Creating jails for custom services</h3><p>By default, fail2ban includes a handful of jail configurations in jail.local. But what if you wanted to create a jail that doesn’t ship with the defaults? There are only 3 things that you need to identify or take note of before creating a new jail:</p><ol><li>Where are the logs stored? Depending on the service, this may be what you’d spend the most time figuring out. For example, NextCloud does not output logs until you install the plugin called “Auditing / Logging”.</li><li>Does the user have access to read the logs? In the case of my Gitea Docker container, the logs were output to a volume mounted to container. Fail2ban was unable to read the logs until chmod was run on it.</li><li>What regex patterns do you need in /etc/fail2ban/filter.d? What jail configurations do you want to setup in /etc/fail2ban/jail.d? Here’s an example that I use for Gitea:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e36b434b5f1db603510ad5ffd7952b36/href">https://medium.com/media/e36b434b5f1db603510ad5ffd7952b36/href</a></iframe><h3>Conclusion</h3><p>As a whole, fail2ban provides a fairly straightforward way to protect your computer against brute force attacks, whether by bots or an actual human. Just by applying the configurations that it ships out of the box, you gain a significant security boost to your servers.</p><p>With a little more effort, configurations can be tailored to suit any service that you wish to protect. Starting today, don’t fail to ban (or should I say “do fail2ban”) unauthorized access to your server!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59887fd7884d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/do-you-fail2ban-unauthorized-server-access-59887fd7884d">Do you fail2ban unauthorized server access?</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I’m NUC Done Yet — Breathing New Life Into an Old Machine]]></title>
            <link>https://medium.com/swlh/im-nuc-done-yet-breathing-new-life-into-an-old-machine-f819f5e1c131?source=rss-522554f64d58------2</link>
            <guid isPermaLink="false">https://medium.com/p/f819f5e1c131</guid>
            <category><![CDATA[hobby]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ren Jie Chong]]></dc:creator>
            <pubDate>Sat, 03 Oct 2020 12:13:51 GMT</pubDate>
            <atom:updated>2020-10-07T10:59:55.926Z</atom:updated>
            <content:encoded><![CDATA[<h3>I’m NUC Done Yet — Breathing New Life Into an Old Machine</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6SCH61OgiyY9Z9zqi2xfA.jpeg" /></figure><p>Several years ago, I purchased Intel’s <a href="https://www.intel.com/content/www/us/en/products/boards-kits/nuc/kits/nuc6i5syh.html">NUC6i5SYH</a> for basic media streaming and light development. With dimensions measuring 115 x 111 x 48 mm and a TDP rating of 15W, it is the smallest, most power-efficient PC that I have ever laid my hands on. This little beast was configured with:</p><ul><li>2x8GB DDR4 RAM</li><li>250GB NVME</li><li>1TB 2.5&quot; SSD</li></ul><p>A few years on, I became convinced that I needed a more powerful rig, especially when dabbling in projects that were power-hungry. That’s right, i’m looking at you, Tensorflow and Android Studio… After the NUC had been replaced by a full-fledged desktop, I sought to re-purpose it into a HTPC / playground for experimental projects.</p><p>This post will walk you through the steps I took to breathe new life into my NUC. If you have an old PC lying around, enjoy getting your hands dirty, and have several hours to spare, do give this guide a go!</p><h3>Electrical Costs</h3><p>In a world fueled by capitalism, we owe it to ourselves to ensure that our locally hosted server makes financial sense. Using <a href="https://www.tp-link.com/sg/home-networking/smart-plug/hs110/">TP-Link’s HS-110</a> smart plug, I measured the consumption of running the server 24/7. These are conservative figures, as the smart plug also measures the consumption from 2 other desktops which are used ~2 hours a day.</p><figure><img alt="Screenshot of the HS-110 smart plug showing the electrical consumption of NUC" src="https://cdn-images-1.medium.com/max/343/1*UMzcde-mPV0X-g32oURsdQ.png" /><figcaption>Screenshot of the HS-110 smart plug showing the electrical consumption of NUC</figcaption></figure><p>The 14.3W above represents the consumption of the NUC when the other 2 desktops are turned off. If we make a <em>really</em> conservative estimate that it consumes 30W on average, then at my current electrical costs of 18 cents/kWh, the NUC costs me about <strong>SGD $3.88/mo</strong> to run 24/7.</p><p>That’s really cheap, considering how much cloud providers such as Digital Ocean are charging.</p><ul><li>(<em>Basic</em>) 1GB RAM + 25GB SSD + 1 CPU … <strong>USD $5/mo</strong></li><li>(<em>Basic</em>) 8GB RAM + 160GB SSD + 4 CPUs … <strong>USD $40/mo</strong></li><li>(<em>Basic</em>) 16GB RAM + 320GB SSD + 8 CPUs … <strong>USD $80/mo</strong></li><li>(<em>Dedicated CPU</em>) 16GB RAM + 50GB SSD + 4 CPUs … <strong>USD $120/mo</strong></li></ul><p>…Ouch!</p><h3>Installing Ubuntu</h3><p>Have you noticed how your computer seems to run more slowly with each Windows OS update? If you have never done so before, you will be surprised how snappy it would be once you flash an Ubuntu image onto your ageing machine.</p><p>Do ensure that you get the Long-Term Support (LTS) version of Ubuntu, as these are more stable and provide security updates for 5 years. At the time of this writing, the LTS version is 20.04. Fun fact — the first 2 digits refers to the year in which it was released (2020), and the next two refers to the month of release (April).</p><p>If you intend to use the machine for browsing the web etc, <a href="https://ubuntu.com/tutorials/install-ubuntu-desktop#download">the Ubuntu Desktop</a> version would make sense as it provides a desktop GUI. However, if you are looking to run it as a server, then the <a href="https://ubuntu.com/download/server">Ubuntu Server</a> download would actually be more suitable, as your machine should be running headless under most circumstances. If you’re undecided, you can always try Ubuntu Server first, then install the Ubuntu Desktop GUI if you change your mind by typing the following in a terminal:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1de451daee63a000f7f6b88c837998d2/href">https://medium.com/media/1de451daee63a000f7f6b88c837998d2/href</a></iframe><p>Your Ubuntu ISO image will then need to be flashed to a USB flash drive. <a href="https://www.balena.io/etcher/">balenaEtcher</a> is the most convenient cross-platform tool for flashing bootable ISO images. Take note that this process will format your thumbdrive, so back up any data first if necessary! Next, with your flash drive plugged in, reboot your machine. This should bring up the GRUB (GRand Unified Bootloader), where you can select the option to “Install Ubuntu”.</p><p>For the rest of this guide, I will refer to the account credentials that you have created during the installation process as [server-username] and [server-password].</p><h3>Setup SSH server</h3><p><em>Note: this section can be tricky as some commands need to be executed on the server, and others on a connecting client. By default, code blocks will be run in server, unless otherwise indicated by a </em><em># TYPE THIS IN CLIENT</em></p><p>Once Ubuntu has been installed, the next step would be to configure and run SSH server — This is important if you’re going to be running your server headless:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9665a766c6d626c3309b0af3a1d57c5f/href">https://medium.com/media/9665a766c6d626c3309b0af3a1d57c5f/href</a></iframe><p>Ensure that OpenSSH is allowed through your firewall:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d097075113b27c29ec4826f9bcac4f7c/href">https://medium.com/media/d097075113b27c29ec4826f9bcac4f7c/href</a></iframe><p>Ensure that SSH public key authentication is enabled in /etc/ssh/sshd_config as this is needed for a later step. Optionally, disable root login unless you absolutely need it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbd73aac348f2d09061e55c0198b331a/href">https://medium.com/media/dbd73aac348f2d09061e55c0198b331a/href</a></iframe><p>Restart the SSHD service, then check that it’s up and running:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b839dd605ca1931c8261bcb50586f2cd/href">https://medium.com/media/b839dd605ca1931c8261bcb50586f2cd/href</a></iframe><p>Use ifconfig to determine your server’s LAN IP address —In most cases, it will be of the form 192.168.1.XXX. You should now be able to SSH into the server using the username and password that you have created for the server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4df0a0754590d704932f288f434be92/href">https://medium.com/media/c4df0a0754590d704932f288f434be92/href</a></iframe><p>Note that using passwords for SSH authentication is cryptographically less secure. Our next course of action is therefore to generate a private-public key pair as a more secure alternative. This is generally performed on a client machine. If you are on OSX or Linux, you should already have the necessary SSH commands at your disposal. If you’re on Windows, please setup Windows Subsystem for Linux (WSL) to save yourself a headache:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6869e39b847a8960b2c88d9d39b40ea/href">https://medium.com/media/d6869e39b847a8960b2c88d9d39b40ea/href</a></iframe><p>If you had used the default key paths, you will find the private key in ~/.ssh/id_rsa and the public key in ~/.ssh/id_rsa.pub. For subsequent steps, we will assume these to be the paths of your private and public keys. In order for the server to allow public key SSH authentications from your client, id_rsa.pub will need to be appended to the ~/.ssh/authorized_keys in your <em>server</em>. Fortunately, with (our temporarily enabled, less-secure) password SSH authentication, we can easily add the public key to the required location in the server using the ssh-copy-id command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b5c94423256f067c1ffaf21b8ee39b7/href">https://medium.com/media/9b5c94423256f067c1ffaf21b8ee39b7/href</a></iframe><p>Satisfy yourself by checking that the server’s ~/.ssh/authorized_keys now contains an entry from the contents of the client’s public key id_rsa.pub.</p><p>To connect to the server using the private key, we need to setup a config file in the client at ~/.ssh/config:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e23d802b64a576fdf505f65d0d6a539/href">https://medium.com/media/8e23d802b64a576fdf505f65d0d6a539/href</a></iframe><p>You should now be able to connect using your private key with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768407a176f00ba83344f3d287357cf5/href">https://medium.com/media/768407a176f00ba83344f3d287357cf5/href</a></iframe><p>Now that public key authentication works, we should disable password authentication by editing /etc/ssh/sshd_config in the server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba1bf1f8c187f1763383d5310466eea2/href">https://medium.com/media/ba1bf1f8c187f1763383d5310466eea2/href</a></iframe><p>Restart the SSH server for the changes to be applied:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19f134a240a273cb3184f9df6a834c8e/href">https://medium.com/media/19f134a240a273cb3184f9df6a834c8e/href</a></iframe><h3>Develop with Docker</h3><p>Docker allows your projects to be run in containers. Think of your private server as one of those space-saving homes with adjustable walls. Each container can then be thought of as a room, and the finite amount of space in the house represents the resources allocated to the Docker engine (CPU, RAM, storage). If you have guests over and require a larger living room, the walls can easily be adjusted to provide the desired configuration. Follow the official documentation for installation of Docker on <a href="https://docs.docker.com/engine/install/ubuntu/">Ubuntu 20.04 here</a>.</p><p>On its own, Docker brings about numerous benefits, but if you wish to take it one step further, the additional benefits from a migration to Kubernetes would probably afflict you with a nosebleed from the excitement. But let’s not get ahead of ourselves… Here are some of the things I love most about Docker.</p><ul><li>Installation &amp; removal is clean as you specify which volumes the container gets access to. On behalf of OCD developers, we thank you, Docker.</li><li>Updating your images is a piece of cake: docker-compose pull &amp;&amp; docker-compose down &amp;&amp; docker-compose up -d -remove-orphans.</li><li>Services can be easily made to start on boot — fare well .service files! All we need is to add restart: unless-stopped to our docker-compose file.</li></ul><p>My preferred way of running docker containers is via docker-compose. This allows us to specify all the relevant ingredients in a yaml file, then fire a single command to bring an instance up. As for keeping things organized, I personally like to keep my projects in folders that are named after the ports that they listen to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f40ece3d3beadc7205d04648267db64f/href">https://medium.com/media/f40ece3d3beadc7205d04648267db64f/href</a></iframe><p>Here’s an example of the docker-compose file for my Plex service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1451710a039aa6a86e2f33432680daaa/href">https://medium.com/media/1451710a039aa6a86e2f33432680daaa/href</a></iframe><p>Once you have your docker images up and running (docker-compose up -d), they can be accessed by any machine that is connected to the same LAN. For example, the above Plex service can be accessed via http://[server-lan-ip]:32400.</p><p>At this point, you may be tempted to start creating all your services, and expose them via port forwarding to your private server… don’t do that! Imagine the nightmare of having to type http://[public-ip-address]:[external-service-port] for a service… or setting up port forwarding in your router each time you create a new service… or the numerous places you need to modify if your ISP decides to change your public IP?</p><p>In a world of instant gratification and short attention spans, we should continue pampering our visitors by allowing all connections to our services through the standard port of 443 for HTTPS connections. There are 3 more tasks that we have to do to achieve this goal:</p><ul><li><strong>TLS Communications</strong>: For our services to be served over secure HTTPS connections</li><li><strong>Reverse Proxy</strong>: To redirect requests to the respective services that are listening on hard-to-remember ports</li><li><strong>Port Forwarding</strong>: To configure our router to forward the necessary ports to our private server (do this last as it pokes holes in your network!)</li></ul><figure><img alt="Diagram showing how we can achieve secure &amp; convenient routing" src="https://cdn-images-1.medium.com/max/1024/1*KKeImRPFxbLThyAmAmat6Q.png" /><figcaption>Diagram showing how we can achieve secure &amp; convenient routing</figcaption></figure><h3>Purchase a domain &amp; setup DNS records</h3><p>Let’s understand the components of a domain:</p><pre>https://hello-world.your.domain</pre><ul><li><strong>Protocol</strong>: https. This determines the nature of the connection that you are trying to establish. Other popular ones include http, ws, wss, webdav, sftp, smb…</li><li><strong>Top-Level Domain (TLD)</strong>: domain. If you’re starting a country or have a burning reason to setup a new TLD, do check this <a href="https://serverfault.com/questions/243316/can-i-create-a-top-level-tld-michael-for-instance">summary of the pre-requisites</a>, such as an evaluation fee of ~USD$185,000. For the rest of us common folk, lets just stick to the available TLDs out there.</li><li><strong>Domain</strong>: your. This is what you’ll need to buy from a registrar! Details coming right up.</li><li><strong>Sub-domain</strong>: hello-world. Once you have bought a domain, it is up to you whatever sub-domains you wish to use for your site, for as long as the total URL length does not exceed 253 characters. This was a huge revelation to me when i first learnt about it!</li></ul><p>You can search for and purchase available domains from any registrar. Here are a few:</p><ul><li><a href="https://www.namecheap.com/">NameCheap</a></li><li><a href="https://www.domain.com/">Domain.com</a></li><li><a href="https://sg.godaddy.com/">GoDaddy</a></li><li><a href="https://www.bluehost.com/">BlueHost</a></li></ul><p>You may want to do <a href="https://www.wpbeginner.com/beginners-guide/how-to-choose-the-best-domain-registrar/">some comparison</a> before deciding on a registrar, but i personally just went with NameCheap without giving it much thought. Just make sure that you pick a domain that doesn’t charge too much from the second year onwards!</p><figure><img alt="Image of NameCheap’s 1st year teaser rates and higher subsequent costs (Retail $x.xx/yr)" src="https://cdn-images-1.medium.com/max/416/1*EhNznqcgSz1CbrNIQZZzHQ.png" /><figcaption>Image of NameCheap’s 1st year teaser rates and higher subsequent costs (Retail $x.xx/yr)</figcaption></figure><p>After securing a domain, you will need to configure the nameservers to use. Most cloud providers host nameservers as well — feel free to consider any of the following:</p><ul><li><a href="https://www.digitalocean.com/">DigitalOcean</a></li><li><a href="https://aws.amazon.com/">AWS</a></li><li><a href="https://cloud.google.com/">Google Cloud</a></li><li><a href="https://www.linode.com/">Linode</a></li><li><a href="https://www.vultr.com/">Vultr</a></li></ul><p>Personally, I went with DigitalOcean out of affection for the fantastic articles that they share about cloud computing.</p><figure><img alt="DNS configurations at both the registrar and the cloud provider" src="https://cdn-images-1.medium.com/max/1024/1*MVFfuOKKW7yrUy_VWntS2Q.png" /><figcaption>DNS configurations at both the registrar and the cloud provider</figcaption></figure><p>For the registrar, all we need to do is to indicate the cloud providers’ nameservers (search for the DNS locations from the registrar’s or cloud providers documentations, or put your Google-Fu to good use). In your cloud provider DNS record settings, you will need to add A records that map hostnames to your private server&#39;s external IP address. You may choose to map the wildcard hostname *.your.domain, or input only specific sub-domains.</p><p>Now, unless your ISP has assured you otherwise, you cannot guarantee that your IP address will remain static. As a result, you need to run periodic updates of your A records to ensure your private server remains accessible. For Digital Ocean, I&#39;m running a cron job at 5 minute intervals using <a href="https://github.com/lummie/dns-dodo">dns-dodo</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a614405f465d7b962796a5d73028dfea/href">https://medium.com/media/a614405f465d7b962796a5d73028dfea/href</a></iframe><p>For the --pat flag, you will need to generate a token via your Digital Ocean account account &gt; API &gt; Tokens/Keys &gt; Personal access tokens. Alternatively, you may consider updating your A records using <a href="https://www.digitalocean.com/docs/apis-clis/doctl/reference/compute/domain/records/update/">doctl</a> as its <a href="https://github.com/digitalocean/doctl">Github page</a> appears to be more well-supported and up-to-date.</p><h3>Setup LetsEncrypt</h3><p><a href="https://letsencrypt.org/">LetsEncrypt</a> is a Certificate Authority that provides free TLS certifications, which can be easily implemented on your site using CertBot.</p><p>After setting up your DNS records and before you continue any further, it is recommended that you go for a break for an hour or two. This is to give time for your DNS records to propagate across the internet, a necessary step for LetsEncrypt to validate that you own the domain you’re registering a wildcard certificate for.</p><p>From the <a href="https://certbot.eff.org/">Certbot page</a>, select My HTTP website is running None of the above on Ubuntu 20.04. There are 2 tabs in the installation instructions page, <strong>make sure to follow the instructions for the Wildcard* option</strong>. Once certbot has been configured correctly, you should see the certificate and certificate keys in the following locations. We will be needing them when we create Nginx server blocks in the next section.</p><pre>/etc/letsencrypt/live/[your-domain]/fullchain.pem;<br>/etc/letsencrypt/live/[your-domain]/privkey.pem;</pre><h3>Install Nginx</h3><p>Without a reverse proxy such as Nginx, a connecting client would need to input a unique port to access a specific service, and the router would need to be configured to forward that external port forwarding configurations will need to map this to the relevant internal port for your private server. The same applies even if internal port equals to the external port for the service.</p><pre>https://your.domain:32400 -&gt; plex on server</pre><p>Nginx saves us from this nightmare by resolving requests to the relevant internal ports based on the hostname that was requested. If you have followed this guide faithfully, you should now be the proud owner of a really large number of sub-domains — we will use this to distinguish the hostname for each service.</p><pre>https://plex.your.domain -&gt; plex on server</pre><p>I personally chose to setup Nginx directly in the host, rather than as a Docker container.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe82b9da35ed75168a117c0cf49e1782/href">https://medium.com/media/fe82b9da35ed75168a117c0cf49e1782/href</a></iframe><p>By default, Nginx configuration files will be installed into /etc/nginx. The configuration files which I have created / modified are as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/471a817ccb0413787befefbbd1f4a850/href">https://medium.com/media/471a817ccb0413787befefbbd1f4a850/href</a></iframe><ul><li><strong>errors</strong>: Non-standard folder. I use this for storing static error 404 css, html and js when an invalid URL is requested.</li><li><strong>nginx.conf</strong>: Default Nginx configuration entry point. Set log locations, data compression settings here. Also take note that by default, it includes all configurations in sites-enabled folder via include /etc/nginx/sites-enabled/*;</li><li><strong>sites-available</strong> and <strong>sites-enabled</strong>: Standard folders. The convention is to place all server block configurations into the sites-available folder, and to create soft links (ln -s) of the configurations that you want to expose in sites-enabled. Personally, i remote into my private server using VS Code’s Remote-SSH extension. With a GUI, I simply drag and drop the configuration files into the relevant folder.</li><li><strong>snippets</strong>: Standard folder for storage of reusable code blocks.</li></ul><p>For almost all my server blocks, I include these basic settings specified in default-proxy-settings.conf:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97afc1365230092ea0f91c279c32e7dd/href">https://medium.com/media/97afc1365230092ea0f91c279c32e7dd/href</a></iframe><p>Likewise, my server blocks also include the LetsEncrypt TLS certificates created by Certbot in the previous section:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94a9bba8fbbf2e0f2973c680c6d40764/href">https://medium.com/media/94a9bba8fbbf2e0f2973c680c6d40764/href</a></iframe><p>To redirect all HTTP requests to the corresponding HTTPS routes, as well as to display a customized 404 page when an invalid route is specified, the following configurations are made in default.conf:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e02e600902668204be6de720d65dc8ad/href">https://medium.com/media/e02e600902668204be6de720d65dc8ad/href</a></iframe><p>Finally, here’s an example of a simple server code block that I’m using for Plex. Nginx provides numerous other settings that you can tweak, it all depends on the requirements of the service you are running. For example, services that permit file uploads (e.g. pushing to a git repository) will likely require configuring client_max_body_size. Refer to their <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html">official list of directives here</a> for more details.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bbf4eab7f6049751da6ddff4a2595e8/href">https://medium.com/media/6bbf4eab7f6049751da6ddff4a2595e8/href</a></iframe><p>In most cases, specifying location / is likely to serve your needs. However, if you need to use more complex regex locations, the <a href="https://www.nginx.com/blog/regular-expression-tester-nginx/">regex nginx tester</a> will be useful in validating your configurations.</p><h3>Port Forwarding</h3><p>At this point, we have setup docker for development; secured a domain from a registrar; setup a wildcard TLS certificate for the domain; and added the TLS certificate to Nginx location blocks to enable secure connections from clients. We have so far not been able to see Nginx at work yet, as external connections are still not being routed to your private server.</p><p>The final step that we need to do is to do port forwarding on your router. A fair word of caution — ensure you have not skipped any of the steps above, and that you have disabled SSH password authentications, or your network would be left pretty exposed.</p><p>Enabling port forwarding depends very much on your router manufacturer. For my ASUS router, it can be found at Advanced Settings &gt; WAN &gt; Virtual Server / Port Forwarding. Take note that by default, HTTP connections occur on port 80, and HTTPS connections occur on port 443. Thus, make sure to forward the external ports 80 and 443 to the internal ports of 80 and 443 of your private server’s LAN IP respectively. Deviating from this means that clients will need to specify the external port number in their browser.</p><p>You may choose to use external ports that differ from the default ports your services listen to (e.g. 22 for SSH) as it makes it more difficult for potential hackers to map the services you have setup.</p><h3>Final thoughts</h3><p>Congratulation on coming this far! It takes a significant amount of effort to setup a private server in a secure way, but it is definitely worthwhile if you have a power-efficient machine. By comparison, even the cheapest offerings by cloud providers cost significantly more despite providing servers with lower specifications.</p><p>Whenever you make a modification to your private server, always pay attention to security — You do not want to compromise all the other devices connected to your LAN. Stay tuned to my next article, where I will <a href="https://medium.com/@renjiechong/do-you-fail2ban-unauthorized-server-access-59887fd7884d">introduce you to fail2ban</a>, a tool that adds another layer of security to your server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f819f5e1c131" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/im-nuc-done-yet-breathing-new-life-into-an-old-machine-f819f5e1c131">I’m NUC Done Yet — Breathing New Life Into an Old Machine</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>