Bash Prompt
https://bash-prompt.net/
Recent content on Bash PromptHugoenThu, 15 Jan 2026 00:00:00 +0000How to Create a Random Password on the Command Line
https://bash-prompt.net/guides/bash-create-random-text/
Thu, 15 Jan 2026 00:00:00 +0000https://bash-prompt.net/guides/bash-create-random-text/<p>Sometimes you need to create a password or other random string of letters and numbers in a script or on the command line. I normally use the excellent tool <a href="https://sourceforge.net/projects/pwgen/">pwgen</a>, but sometimes that is not available on the system you are working on.</p>
<p>When <code>pwgen</code> isn’t available, you can sanitize the output of <code>/dev/urandom</code> so that you only get text and numbers. The following command will output a 10-character string:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cat /dev/urandom | tr -d -c <span style="color:#f92672">[</span>:alnum:<span style="color:#f92672">]</span> | head -c <span style="color:#ae81ff">10</span>
</span></span></code></pre></div><ul>
<li><code>cat /dev/urandom</code> This outputs /dev/urandom to stdout; you can’t use this as is contains lots of data that isn’t a letter or number.</li>
<li><code>tr</code> The translate command
<ul>
<li><code>-d</code> Deletes the characters that match the filter.</li>
<li><code>-c</code> Reverses the deletion, instead printing the characters that it would have deleted and deleting the others.</li>
<li><code>[:alnum:]</code> Letters and numbers.</li>
</ul>
</li>
<li><code>head -c 10</code> Prints the first 10 bytes.</li>
</ul>
<p>Change the <code>head -c 10</code> to make the output as long as you need it to be.</p>Quickly Create Temporary Files and Directories with mktemp
https://bash-prompt.net/guides/bash-temp/
Wed, 03 Dec 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-temp/<p>When scripting, it is often necessary to store some temporary data. This is not persistent data, it does not hold any important information that needs to be retained for longer than the execution of the script.</p>
<p>I’ve used lots of methods to create temporary directories and files that I end up recreating every time.</p>
<p>That is, until I found <a href="https://www.mktemp.org/docs/mktemp.man/">mktemp</a>.</p>
<h2 id="how-to-use-mktemp">How To Use <code>mktemp</code></h2>
<p>By default, <code>mktemp</code> will create files and directories under <code>/tmp/</code>. This means they will be deleted on reboot on almost all modern Linux distributions.</p>Automatic SSH Lockout
https://bash-prompt.net/guides/bash-ssh-persourcepenalties/
Sun, 30 Nov 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-ssh-persourcepenalties/<p>I recently upgraded a server to Debian Trixy, and I noticed some new lines in <code>/var/log/auth.log</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>2025-11-30T00:17:48.220870+00:00 WEB sshd<span style="color:#f92672">[</span>55238<span style="color:#f92672">]</span>: srclimit_penalise: ipv4: new 1.2.3.4/32 active penalty of 1s seconds <span style="color:#66d9ef">for</span> penalty: connections without attempting authentication
</span></span></code></pre></div><p>After a little searching, I found that the new version of the SSH server included with Trixy had a new directive <a href="https://www.man7.org/linux/man-pages/man5/sshd_config.5.html"><em>PerSourcePenalties</em></a>.</p>
<p>This directive allows you to automatically deny login requests from IPs that have committed login failures and exceeded your configured maximum. Like Fail2Ban, but not using a firewall.</p>How to Generate Text-to-Speech Locally
https://bash-prompt.net/guides/bash-piper-audio/
Mon, 22 Sep 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-piper-audio/<p>I recently looked at generating spoken audio from text using <a href="https://bash-prompt.net/guides/bash-text-to-speech/">here</a>. I have found another way to do this, but locally, instead of sending all the data to Google.</p>
<p>The tool that I used is called <a href="https://github.com/OHF-Voice/piper1-gpl">piper1-gpl</a>.</p>
<h2 id="install-piper">Install Piper</h2>
<p>Use the Python package manager <a href="https://pypi.org/project/pip/">pip</a> to get it installed:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>pip install piper-tts
</span></span></code></pre></div><p>You may need to use your distro’s package manager to get <code>pip</code> installed if it’s not present.</p>
<h2 id="choose-a-voice">Choose a voice</h2>
<p>Next, you need to choose a voice to read the text. The following command will print a list of available voices:</p>Simplify WireGuard User Management with Vanity Keys
https://bash-prompt.net/guides/wireguard-vanity-key/
Sat, 23 Aug 2025 00:00:00 +0000https://bash-prompt.net/guides/wireguard-vanity-key/<p><a href="https://www.wireguard.com/">WireGuard</a> is an excellent replacement for OpenVPN. If you haven’t already started using it, check out my <a href="https://bash-prompt.net/guides/wireguard-setup/">quick start guide</a>.</p>
<p>A small annoyance I’ve had with WireGuard is that when I want to see who is connected, their data transfer, etc., the <code>wg</code> output only identifies them by their public key. E.g.:</p>
<pre tabindex="0"><code>sudo wg
peer: sX4eqmye8hqC2eu+9zJuS6Nh56UdV/foyNd5hK+gwjQ=
preshared key: (hidden)
endpoint: 1.1.1.1:54294
allowed ips: 10.0.0.2/32
latest handshake: 19 hours, 41 minutes, 52 seconds ago
transfer: 18.55 MiB received, 383.54 MiB sent
peer: /KmQaPQLRxqKOYyxvU80Y9EhspWm8UARfgi+PmVbgBY=
preshared key: (hidden)
endpoint: 2.2.2.2:56528
allowed ips: 10.0.0.3/32, 2a01:4ff:f0:e625::/128
latest handshake: 3 days, 20 hours, 55 minutes, 5 seconds ago
transfer: 1.72 MiB received, 1.96 MiB sent
</code></pre><p>To determine which user each peer corresponds to, I need to <code>grep</code> through the user configuration files for the key.</p>Text-to-Speech on the Command Line
https://bash-prompt.net/guides/bash-text-to-speech/
Sun, 17 Aug 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-text-to-speech/<p><strong>Edit</strong> I have found a new way to do this locally that gives excellent results. You can read the guide <a href="https://bash-prompt.net/guides/bash-piper-audio/">here</a> <strong>/Edit</strong></p>
<p>I’ve been practicing my Spanish recently, and I wanted a tool to output spoken Spanish from a text file as I read along.</p>
<p>I tried a few tools like <a href="https://github.com/espeak-ng/espeak-ng/">espeak-NG</a>, <a href="https://pypi.org/project/pyttsx3/">pyttsx3</a> and
<a href="http://festvox.org/festival/">Festival</a> but the results were a little robotic.</p>
<p>The tool that produced the best results was <a href="https://github.com/pndurette/gTTS">gTTS</a>. This tool sends written text to Google
Translate’s text-to-speech API and returns the text in spoken audio. There are many languages available (get the full list with <code>gtts-cli --all</code>) and the audio out can either be saved to a file or
sent to stdout.</p>cURL to an IP address With a Hostname
https://bash-prompt.net/guides/bash-curl-ip-hostname/
Sun, 13 Apr 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-curl-ip-hostname/<p>I recently modified this website to be accessible via IPv6 so I needed to test that Apache would respond with the site when accessed over IPv6.</p>
<p><a href="https://curl.se/">cURL</a> allows access to an IP address of a server and supply a hostname, <code>bash-prompt.net</code>. This means that cURL will initiate the HTTPS connection to the IP address and then reply with the correct website when it receives the hostname.</p>
<p>The cURL command to do this is as follows:</p>Whois and IP Address Info
https://bash-prompt.net/guides/bash-whois-ip/
Fri, 11 Apr 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-whois-ip/<p>We typically use the <a href="https://github.com/rfc1036/whois">whois</a> command to get information about domain names. <code>whois</code> can also get the organization information about the company that an IP address is registered to.</p>
<p>Every IP address is registered to an organization by an IP authority. You can find the list authorities <a href="https://www.iana.org/numbers">here</a>. When an organization requests and is allocated an IP address, typically in a block, they must supply information about their organization such as country, contact information and an abuse reporting email.</p>Using Column to Make Bash More Understandable
https://bash-prompt.net/guides/bash-column/
Tue, 25 Mar 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-column/<p>Sometimes the output of commands or the information in log files is not formatted very well which makes it difficult to understand.</p>
<p>For example, here are the top ten lines of a CPU benchmark log file:</p>
<pre tabindex="0"><code>$ head benchmark.log
#round load sleep performance powersave percentage
0 50000 50000 53105 56467 94.045
1 100000 100000 103600 109100 94.959
2 150000 150000 153215 159666 95.960
3 200000 200000 203750 210340 96.867
4 250000 250000 254398 262572 96.887
5 300000 300000 303918 312696 97.193
6 350000 350000 354797 363481 97.611
7 400000 400000 404626 413001 97.972
</code></pre><p>The data does not align with the labels on the top line making it harder to parse. If we pass this into <a href="https://github.com/util-linux/util-linux">column</a> as standard input <code>column</code> will neatly print the same information in understandable columns:</p>Some Alternatives to dd
https://bash-prompt.net/guides/bash-dd-alternatives/
Thu, 27 Feb 2025 00:00:00 +0000https://bash-prompt.net/guides/bash-dd-alternatives/<p><a href="https://ss64.com/bash/dd.html">dd</a> is a very old command. It was published over 50 years ago in 1974 for Unix. This age makes the syntax of its commands quite unusual. Given that this command is frequently used to overwrite partitions and entire storage devices the unusual nature of its command syntax is dangerous. It’s a rite of passage for every Linux Sysadmin to <code>dd</code> over something viable, destroying it.</p>
<p>There are now more modern commands that can perform the same job as <code>dd</code> using much more standard syntax.</p>Debugging Bash Scripts - Part 5 - Jump forward in a script
https://bash-prompt.net/guides/bash-debugging-5/
Mon, 18 Mar 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-debugging-5/<p>Here is the list of all the Bash debugging posts:</p>
<ul>
<li><a href="https://bash-prompt.net/guides/bash-debugging-1">Verbose Output</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-2">Using exit command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-3">Using echo command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-4">Using ShellCheck</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-5">Jummping Forward</a></li>
</ul>
<p>The <code>exit</code> command will allow you to halt a script without executing everything after the <code>exit</code> command.</p>
<p>If you want to do the opposite and skip some of the script there is no builtin command to do this. This is useful for debugging so that you can work only on the problem section without re-executing a prior portion of the scrip.</p>Debugging Bash Scripts - Part 3 - Using echo
https://bash-prompt.net/guides/bash-debugging-3/
Sun, 17 Mar 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-debugging-3/<p>Here is the list of all the Bash debugging posts:</p>
<ul>
<li><a href="https://bash-prompt.net/guides/bash-debugging-1">Verbose Output</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-2">Using exit command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-3">Using echo command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-4">Using ShellCheck</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-5">Jummping Forward</a></li>
</ul>
<p>This debugging tool is useful in your Bash scripts and also in any Bash one-liners that you write.</p>
<p>The <code>echo</code> tool will print any input you give it. Most importantly, it will not execute any commands that are included in the input you give it but it will expand variables, wildcards, etc to show you everything that would happen when you run that command.</p>Debugging Bash Scripts - Part 4 - ShellCheck
https://bash-prompt.net/guides/bash-debugging-4/
Sun, 17 Mar 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-debugging-4/<p>Here is the list of all the Bash debugging posts:</p>
<ul>
<li><a href="https://bash-prompt.net/guides/bash-debugging-1">Verbose Output</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-2">Using exit command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-3">Using echo command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-4">Using ShellCheck</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-5">Jummping Forward</a></li>
</ul>
<p>This one is pretty simple. Either install <a href="https://www.shellcheck.net/">ShellCheck</a> with your package manager or use the <a href="https://www.shellcheck.net/">website</a> tool to check your scripts.</p>
<p>It will check for any buggy code and also offer syntax advice like quoting variables.</p>
<p>The following script won’t run as it has a syntax error:</p>
<pre tabindex="0"><code>#!/bin/bash
for i in {1..10}: do
mkdir $i
done
</code></pre><p>However, the error on execution isn’t too easy to understand:</p>Debugging Bash Scripts - Part 1 - Verbose Output
https://bash-prompt.net/guides/bash-debugging-1/
Sat, 02 Mar 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-debugging-1/<p>Here is the list of all the Bash debugging posts:</p>
<ul>
<li><a href="https://bash-prompt.net/guides/bash-debugging-1">Verbose Output</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-2">Using exit command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-3">Using echo command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-4">Using ShellCheck</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-5">Jummping Forward</a></li>
</ul>
<p>When you run a Bash script it will only usually print the output of the commands that you execute. This is fine until you need to figure out why it isn’t doing what you want.</p>
<p>Bash comes with a couple of options that will show you exactly what is being run and also print out the lines of the script in the order of the execution output, including comments.</p>Debugging Bash Scripts - Part 2 - Using exit
https://bash-prompt.net/guides/bash-debugging-2/
Sat, 02 Mar 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-debugging-2/<p>Here is the list of all the Bash debugging posts:</p>
<ul>
<li><a href="https://bash-prompt.net/guides/bash-debugging-1">Verbose Output</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-2">Using exit command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-3">Using echo command</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-4">Using ShellCheck</a></li>
<li><a href="https://bash-prompt.net/guides/bash-debugging-5">Jummping Forward</a></li>
</ul>
<p>The <code>exit</code> command in a Bash scrip will immediatly cause the scrip to stop as soon it is <code>exit</code> is executed.</p>
<p>This is very useful in two ways:</p>
<ol>
<li>This can be used to stop the scrip immediatly after your problem section all the remaining script doesn’t get run.</li>
<li>You can put it into a loop so that it only performs one iteration.</li>
</ol>
<p>Using the script from <em>Part 1</em>:</p>How To Use Xargs To Execute Processes In Parallel
https://bash-prompt.net/guides/bash-xargs-parallel/
Mon, 05 Feb 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-xargs-parallel/<p>We frequently have to run many processes from a script. The default behavior is that the processes or jobs are run serially. That is to say that each new process will start when the one before finishes.</p>
<p>On modern multi-core systems, this is wasting a lot of CPU resources and time.</p>
<p><a href="https://www.gnu.org/software/findutils/">xargs</a> is a complex tool that comes with the ability to run processes in parallel.</p>
<p>The general structure of parallel processing with <code>xargs</code> is as follows:</p>How To Downsize an MP3 Audiobook to OPUS
https://bash-prompt.net/guides/bash-mp3-to-opus/
Tue, 30 Jan 2024 00:00:00 +0000https://bash-prompt.net/guides/bash-mp3-to-opus/<p>I like to listen to audiobooks on my older phone. They can get quite large so I thought I would try to transcode (change their encoding format) from the older MP3 to the newer <a href="https://opus-codec.org/">Opus</a></p>
<p>Opus has a useful setting to encode voice-optimized encoding for voice-over-IP applications. Audiobooks are only someone speaking so this is a perfect application for this setting</p>
<p>I downloaded <a href="https://librivox.org/don-quixote-vol-1-by-miguel-de-cervantes-saavedra/">Don Quixote</a> from <a href="https://librivox.org/">LibreVox</a> the free public domain audiobooks as a test file.</p>How to Quickly Check If A Port Is Open With netcat
https://bash-prompt.net/guides/bash-netcat-open-port/
Tue, 12 Dec 2023 00:00:00 +0000https://bash-prompt.net/guides/bash-netcat-open-port/<p>Sometimes you need to check if a port is open and available e.g. not firewalled, from your current location.</p>
<p>The following <a href="http://netcat.sourceforge.net/">netcat</a> command will instantly tell you if you a port is open and you can connect to it on a remove server:</p>
<pre tabindex="0"><code>netcat -w1 -z -v <HOST> <PORT>
</code></pre><p>E.g.:</p>
<pre tabindex="0"><code>netcat -w1 -z -v bash-prompt.net 443
</code></pre><p>If the port is open you’ll get the following response:</p>
<pre tabindex="0"><code>$ netcat -w1 -z -v bash-prompt.net 443
bash-prompt.net [5.161.150.90] 443 (https) open
</code></pre><p>And if it’s closed:</p>Bash Oneliners - Count, Sort, and Print Objects
https://bash-prompt.net/guides/bash-oneliners-sort/
Mon, 04 Sep 2023 00:00:00 +0000https://bash-prompt.net/guides/bash-oneliners-sort/<p>There are several Bash one-liners that I’ve been shown by the talented Linux admins I’ve had the pleasure of working with over the years.</p>
<p>This one will take something you’re interested in, say IPs from a log file, and print them in a sorted list.</p>
<p>For example, say I wanted to see the bots trying to access SSH. The <code>/var/log/auth.log</code> (Debian) prints lines like the following:</p>
<pre tabindex="0"><code>2023-09-04T06:58:01.540076+00:00 HOST sshd[249345]: Invalid user blank from 1.1.1.1 port 20082
</code></pre><p>First, we need to get the IP addresses:</p>How to Trace An HTTP/HTTPS Request with cURL
https://bash-prompt.net/guides/bash-curl-trace-page-request/
Tue, 08 Aug 2023 00:00:00 +0000https://bash-prompt.net/guides/bash-curl-trace-page-request/<p>Configuring a web server like Apache2 or NGINX can get quite complicated given the number of elements that are now involved in serving networked data.</p>
<p>The <a href="https://curl.se/">cURL</a> command line tool provides excellent options to print out exactly what it’s doing when it requests an object from a remote server.</p>
<p>Simply use the following options when using cURL to print the complete interaction between cURL and the server:</p>
<pre tabindex="0"><code>curl -vIL <URL>
</code></pre><p>Running cURL with these options against <strong><a href="https://bash-prompt.net">https://bash-prompt.net</a></strong> gives the following output:</p>How to Redirect an HTTP Site From WWW to non-WWW (or the other way around)
https://bash-prompt.net/guides/apache-redirect-www/
Mon, 31 Jul 2023 00:00:00 +0000https://bash-prompt.net/guides/apache-redirect-www/<p>I like to run my sites without a www. You’re looking at this site like that e.g. <strong><a href="http://bash-prompt.net">http://bash-prompt.net</a></strong>.</p>
<p>Some traffic always arrives at <strong><a href="http://www.bash-prompt.net">http://www.bash-prompt.net</a></strong> which sometimes breaks things, especially with dynamic sites.</p>
<p>This problem can be solved using the Apache module <a href="https://httpd.apache.org/docs/current/mod/mod_rewrite.html">mod_rewrite</a>. But I’ve had problems with that and it’s an overcomplicated way to do things.</p>
<p>The problem is more easily solved using Apache’s <code>Redirect</code> directive supplied by <a href="https://httpd.apache.org/docs/2.4/mod/mod_alias.html">mod_alias</a>.</p>
<h2 id="step-1---preparation">Step 1 - Preparation</h2>
<p>First, make sure that the <code>mod_alias</code> module is loaded and reload Apache:</p>How to Redirect an HTTPS Website From WWW to non-WWW (or the other way around)
https://bash-prompt.net/guides/apache-redirect-https/
Sun, 30 Jul 2023 00:00:00 +0000https://bash-prompt.net/guides/apache-redirect-https/<p>I like to run my sites without a www. You’re looking at this site like that i.e. <strong><a href="https://bash-prompt.net">https://bash-prompt.net</a></strong>.</p>
<p>Some traffic always arrives at <strong><a href="https://www.bash-prompt.net">https://www.bash-prompt.net</a></strong> which sometimes breaks things, especially with dynamic sites.</p>
<p>This problem can be solved using the Apache module <a href="https://httpd.apache.org/docs/current/mod/mod_rewrite.html">mod_rewrite</a>. But I’ve had problems with that and it’s an overcomplicated way to do things.</p>
<p>The problem is more easily solved using Apache’s <code>Redirect</code> directive supplied by <a href="https://httpd.apache.org/docs/2.4/mod/mod_alias.html">mod_alias</a>.</p>
<p>What we’re going to do is to:</p>How to Benchmark SSL Performance
https://bash-prompt.net/guides/openssl-benchmark/
Thu, 27 Jul 2023 00:00:00 +0000https://bash-prompt.net/guides/openssl-benchmark/<p><a href="https://www.openssl.org/">OpenSSL</a> is the default package for managing certificates and serving HTTPS pages on Linux servers. It’s how you’re seeing this page via HTTPS right now.</p>
<p>You might be interested in seeing how you can benchmark how fast your server can serve HTTPS requests as a part of tuning it.</p>
<p>the <code>openssl</code> command comes with this ability built in.</p>
<p>The following command will prompt <code>openssl</code> to make as many requests as it can for 30s and print the results:</p>How to Flush Your systemd-resolved Cache
https://bash-prompt.net/guides/bash-flush-systemd-resolve/
Thu, 13 Jul 2023 00:00:00 +0000https://bash-prompt.net/guides/bash-flush-systemd-resolve/<p>DNS caching is a good thing. When your local resolver, in this case, <a href="https://www.freedesktop.org/software/systemd/man/systemd-resolved.html">systemd-resolved</a>, looks up a domain’s (or hostname’s) IP address it retains or caches, that IP address on your machine so that it doesn’t need to query the nameservers again. This is faster for you and reduces the load on the nameservers.</p>
<p>However, this can become a problem if you’re changing DNS records and need to see the live remote records from the nameservers and not the local cached records.</p>A Shorter Way To Send stdout and stderr to /dev/null
https://bash-prompt.net/guides/bash-stdout-stderr/
Sat, 10 Jun 2023 00:00:00 +0000https://bash-prompt.net/guides/bash-stdout-stderr/<p>When we’re scripting or running a command on Linux we sometimes don’t want any output from the command. This output may be the success message from the command on <a href="https://linux.die.net/man/3/stdout">stdout</a> (standard output) or an error message on <a href="https://linux.die.net/man/3/stderr">stderr</a> (standard error).</p>
<p>The usual way to do this is with the classic:</p>
<pre tabindex="0"><code>$ <COMMAND> 2>&1 >/dev/null
</code></pre><p>This redirects <code>stderr</code> into <code>stdout</code> and then sends <code>stdout</code> to the bitbucket <code>/dev/null</code>.</p>
<p>Instead, we can use the following:</p>How To Reset Sudo Password Lockout
https://bash-prompt.net/guides/bash-sudo-reset/
Sat, 13 May 2023 00:00:00 +0000https://bash-prompt.net/guides/bash-sudo-reset/<p>Entering a password incorrectly too many times happens to all of us. It could be entering the desktop or running a <a href="https://www.sudo.ws/sudo/">sudo</a> command from the command line as a user. After 3 failed attempts <code>sudo</code> will lock that user account from logging in for a period.</p>
<p>Here’s how to reset <code>sudo</code> so they can log in again immediately. Here is me deliberately entering an incorrect password three times for user <em><!-- raw HTML omitted --></em>:</p>Quickly Create a WireGuard Server and Clients
https://bash-prompt.net/guides/wireguard-setup/
Tue, 02 May 2023 00:00:00 +0000https://bash-prompt.net/guides/wireguard-setup/<h2 id="introduction">Introduction</h2>
<p><a href="https://www.wireguard.com/">WireGuard</a> is a modern <em>V</em>irtual <em>P</em>rivate <em>N</em>etwork (VPN) server that allows you to securely route your data between your Android, iPhone phone, or Linux, Windows, or OSX computer. The older, open-source standard for creating your own VPN was <a href="https://openvpn.net/">OpenVPN</a> which is, when compared to WireGuard, much harder to set up and configure.</p>
<p>In this guide, I will walk you through installing and configuring the WireGuard server and creating your first client configuration file. You can be up and running in 10 minutes or less because WireGuard was created to be secure by default obviating the need for complicated tweaking and tuning.</p>How To Generate A Let's Encrypt Certificate For Several Hostnames
https://bash-prompt.net/guides/certbot-multiple-domains/
Sun, 25 Dec 2022 00:00:00 +0000https://bash-prompt.net/guides/certbot-multiple-domains/<p>Over on my personal website <a href="https://elliotcooper.com">https://elliotcooper.com</a> I encountered a problem when I created a redirect from <code>https://www.elliotcooper.com</code> to <code>https://elliotcooper.com</code>. The web server, in this case, Apache2, first negotiates the HTTPS connection before doing the redirect.</p>
<p>This was a problem because the <a href="https://letsencrypt.org/">Let’s Encrypt</a> certificate I generated was only valid for the Common Name (CN) <code>elliotcooper.com</code>. This caused my browser to display a certificate warning as the certificate didn’t include the CN <a href="https://www.ellitocooper.com">www.ellitocooper.com</a>.</p>
<p>I’ve also noticed this elsewhere when I click on links that are different, usually it’s the <code>www</code>s, to the CN in the certificate.</p>Switch Your Bash One-Liner Into Your Editor
https://bash-prompt.net/guides/bash-edit-command/
Fri, 19 Nov 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-edit-command/<p>We all write over-long Bash one-liners to get something done. They can get difficult to edit when they start taking up more than one line.</p>
<p>Fortunately, Bash allows you to switch from Bash to your editor so you can easily continue editing the command in a real editing environment and run it on exit.</p>
<p>All you need to do is to hit:</p>
<pre tabindex="0"><code>CTRL+x CTRL+e
</code></pre><p>while your working on your command. When you do you and your command will be loaded into whatever editor you have set as you <code>$EDITOR</code> environment variable.</p>Quickly Test Network Speed Between Two Servers
https://bash-prompt.net/guides/quick-network-test/
Thu, 28 Oct 2021 00:00:00 +0000https://bash-prompt.net/guides/quick-network-test/<p>Quickly discovering the speed between two Linux servers can often be a chore of copying large files around.</p>
<p>There is a better way with <a href="https://iperf.fr/">iperf</a>.</p>
<p><code>iperf</code> can be used to quickly setup a server and client process on two Linux servers and report the max network throughput between them.</p>
<h2 id="server">Server</h2>
<p>Run the following command on the server machine:</p>
<pre tabindex="0"><code>iperf -s -i 10
</code></pre><ul>
<li><code>-s</code> - Create a server that will listen on TCP 5001.</li>
<li><code>-i 10</code> - Print a speed report every 10 seconds.</li>
</ul>
<h2 id="client">Client</h2>
<p>On the client run the following command:</p>Quickly Review Linux Server Resource Usage
https://bash-prompt.net/guides/linux-server-resource-use/
Tue, 12 Oct 2021 00:00:00 +0000https://bash-prompt.net/guides/linux-server-resource-use/<p>A common job for a system administrator is to troubleshoot a Linux server to find out why it’s running slowly.</p>
<p>The following command will give you a great overview and should only take less than a minute to review.</p>
<h2 id="uptime"><code>uptime</code></h2>
<p>The uptime command will, naturally, tell you the uptime of your server but will also give you the load averages. This will tell you how busy your server is and has been in the recent past.</p>How To Get A List Of URLs From A Website
https://bash-prompt.net/guides/test-edit/
Sun, 12 Sep 2021 00:00:00 +0000https://bash-prompt.net/guides/test-edit/<p>A fairly frequent job of a sysadmin is to do some benchmarking of a website. The first requirement of this is that you have some URLs to give to the benchmarking tool.</p>
<p>I have found that getting a list of all the site’s URLs for assets like HTML pages, images, CSS files etc makes the test a bit more representative.</p>
<p>The following command will very quickly spider a website and generate a text file of all the URLs that it finds:</p>How To Get A List Of URLs From A Website
https://bash-prompt.net/guides/wget-spider-site/
Sun, 12 Sep 2021 00:00:00 +0000https://bash-prompt.net/guides/wget-spider-site/<p>A fairly frequent job of a sysadmin is to do some benchmarking of a website. The first requirement of this is that you have some URLs to give to the benchmarking tool.</p>
<p>I have found that getting a list of all the site’s URLs for assets like HTML pages, images, CSS files etc makes the test a bit more representative.</p>
<p>The following command will very quickly spider a website and generate a text file of all the URLs that it finds:</p>Easily Speed Up Apache With mod_cache by 65%
https://bash-prompt.net/guides/apache-mod-cache/
Fri, 10 Sep 2021 00:00:00 +0000https://bash-prompt.net/guides/apache-mod-cache/<p>Not too many people know that <a href="https://httpd.apache.org/">Apache2</a> provides a simple caching module <a href="https://httpd.apache.org/docs/2.4/mod/mod_cache.html">mod_cache</a>.</p>
<p>It’s super simple to enable for a static site like this one and gave me a %65 performance increase!</p>
<p>Here’s how.</p>
<h2 id="enable-the-apache2-mods">Enable the Apache2 mods</h2>
<p>First, enable the two cache mods that are installed along with Apache2:</p>
<pre tabindex="0"><code>a2enmod cache
a2enmod cache_disk
systemctl reboot
</code></pre><h2 id="configure-the-virtualhost-file">Configure the VirtualHost file</h2>
<p>Next, open your site’s VirtualHost file and add the following code block between the <code><VirtualHost></code> tags:</p>Practice Using mdadm With Virtual Block Devices
https://bash-prompt.net/guides/bash-mdadm-practice/
Mon, 06 Sep 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-mdadm-practice/<p><a href="https://www.man7.org/linux/man-pages/man8/mdadm.8.html"><code>mdadm</code></a> is the tried and trusted software RAID tool for Linux. You might think that getting some practice with <code>mdadm</code> is difficult because you need several storage devices.</p>
<p>That’s not true as you can simple create some virtual devices to practice on.</p>
<p>Here’s how.</p>
<h2 id="create-the-virtual-block-devices">Create the virtual block devices</h2>
<p>Use <a href="https://www.gnu.org/software/coreutils/"><code>dd</code></a> to create three 32MB files:</p>
<pre tabindex="0"><code>dd if=/dev/zero of=disk1 bs=1M count=32
dd if=/dev/zero of=disk2 bs=1M count=32
dd if=/dev/zero of=disk3 bs=1M count=32
</code></pre><p>Next, map them to loopback block devices using <code>losetup</code>:</p>A Simple Guide To Getting Started With SSH Certificates
https://bash-prompt.net/guides/ssh-certificates/
Fri, 03 Sep 2021 00:00:00 +0000https://bash-prompt.net/guides/ssh-certificates/<p>SSH keys are the best way of logging into Linux servers. But traditional keys have their limitations.</p>
<p><strong>They never expire</strong></p>
<p>Organizations commonly have workers that need access access to a system for a limited time, employees, move on etc. Managing this is possible by by removing keys as needed but SSH certificates have an expiry date built right into them.</p>
<p>You even can issue new daily certificates to everyone every morning making them worthless the following day.</p>Create A Simple Desktop Notification From Bash With notify-send
https://bash-prompt.net/guides/simple-desktop-notify/
Thu, 19 Aug 2021 00:00:00 +0000https://bash-prompt.net/guides/simple-desktop-notify/<p>Some Bash commands take a long time to finish and provide no estimate for when that will happen. This means that you have to keep switching back to its terminal to check its status.</p>
<p>That’s a pain that interrupts your workflow.</p>
<p>Instead, use this simple command to create a popup notification on your desktop that will let you know the process has finished.</p>
<p>First, install <a href="https://developer.gnome.org/libnotify/"><code>libnotify</code></a> on your machine.</p>
<p>Next, use the following simple syntax to create a desktop notification when your command has finished:</p>How To Monitor Network Activity With IPTraf-ng
https://bash-prompt.net/guides/iptraf/
Tue, 10 Aug 2021 00:00:00 +0000https://bash-prompt.net/guides/iptraf/<p>Some Bash tools are so good that then end up being the goto tool for a particular application year after year.</p>
<p><a href="https://sourceforge.net/projects/iptraf-ng/">IPTraf</a> now <strong>IPTraf-ng</strong>, is one such tool. I have been using it for at least 20 years and nothing has come close to replacing it for live network monitoring.</p>
<p>Just fire it up with <code>iptraf-ng</code> to get started. This will bring you to a choice menu:</p>
<p><img src="https://bash-prompt.net/images/guides/iptraf/iptraf-first-menue.png" alt=""></p>
<h2 id="ip-traffic-monitor">IP traffic monitor</h2>
<p>This section allows you to view your network traffic by connected IP address over an interface, either individually or all together. The fist menu shows this clearly:</p>How To Add An APT GPG Key
https://bash-prompt.net/guides/bash-apt-add-key/
Sun, 08 Aug 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-apt-add-key/<p>A common security measure implemented by APT repository maintainers is to sign the packages they distribute. This ensures that the packages you are installing are the authorized and unmodified packages issued by the package maintainers an no one else.</p>
<p>It can be a little confusing how to import the key into APT to install the new package in the first place.
Here’s the easy way.</p>
<p>I just had to installed the excellent web log analyzer <a href="https://goaccess.io/">GoAccesss</a> so I will use it as an example.</p>A Simple Bash Help Case Statement
https://bash-prompt.net/guides/bash-help-case-statement/
Mon, 02 Aug 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-help-case-statement/<p>Bash scripts tend to follow a life time. They start as a long bash command dumped into a file for future use. They then get formatted and prettified when others want to use them.</p>
<p>When your script gets used by others it’s a great idea to add some basic error checking and help information. Let’s look at how to do this.</p>
<p>The example script, <code>print-string.sh</code>, does nothing else but print a string passed to it. Here it is:</p>Bash Set Options For Security
https://bash-prompt.net/guides/bash-set-options/
Wed, 28 Jul 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-set-options/<p>We all write Bash scripts. They are convenient, fast and <strong>powerful</strong>. But how to make them safer?</p>
<p>Bash provides some simple options that you can set at the beginning of every script (unless you have a good reason not to) that will keep things a little safer by causing the script to exit when unexpected stuff happens.</p>
<p>These options are configured with the <code>set</code> option that you can read all about <a href="https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html">here</a>.</p>Bash Idioms For Portability
https://bash-prompt.net/guides/bash-portability/
Wed, 21 Jul 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-portability/<p>The life of one of your Bash scripts is hard to reckon when you first write it. They often end up at opposite ends of the company on very different systems. This makes it a good idea to make them as portable as possible.</p>
<p>A couple of easy wins here are to replace the traditional interpreter line and drop <code>echo</code> commands.</p>
<h2 id="script-interpreter">Script Interpreter</h2>
<p>The traditional interpreter line at the start of the file usually links to the binary of the shell that you want the script to get executed by. E.g. for Bash</p>Massively Speed Up DNF
https://bash-prompt.net/guides/bash-dnf-speed/
Wed, 07 Jul 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-dnf-speed/<p>I just spun up a new CentOS 8 VM and ran the mandatory initial update and was rather surprised to see single packages downloading at 50KBps. I think 1998 would like their acceptable transfer speeds back!</p>
<p>It turns out that a couple of changes to your <code>dnf.conf</code> file will get you back into the 21st century.</p>
<p>Just edit your <code>dnf.conf</code> file:</p>
<pre tabindex="0"><code>nano /etc/dnf/dnf.conf
</code></pre><p>And make sure you have the following two lines:</p>How To Mirror A Website With wget
https://bash-prompt.net/guides/wget-mirror-website/
Wed, 30 Jun 2021 00:00:00 +0000https://bash-prompt.net/guides/wget-mirror-website/<p>A common requirement for backups or just to have a local copy of a website is to mirror it. This is easily done with the <a href="http://www.gnu.org/software/wget/">wget</a> tool.</p>
<p>wget is a command line tool for retrieving files over a network. As is common with the older Linux tools it has a huge number of really useful options. For this use case wget comes with a bunch options to access a website and by following all the internal links download the entire site to a local, browsable copy.</p>Some Useful GNU nano Settings
https://bash-prompt.net/guides/nanorc-settings/
Thu, 27 May 2021 00:00:00 +0000https://bash-prompt.net/guides/nanorc-settings/<p>The <a href="https://www.nano-editor.org/">GNU nano</a> is a superb Linux text editor. And you absolutely should use it. It’s not a fully-featured <a href="https://en.wikipedia.org/wiki/Integrated_development_environment">IDE</a> nor does it claim to be.</p>
<p>If you’re looking for a fast, lightweight editor that is usually installed by default (or available in the standard repos of every distro) then you should take a look at nano.</p>
<p>I use nano for all my processional Linux administration and content creation. With a few tweaks you can turn nano into a capable editor that will meet your everyday needs.</p>Use Explainshell To Decode A Bash Command
https://bash-prompt.net/guides/explainshell/
Wed, 21 Apr 2021 00:00:00 +0000https://bash-prompt.net/guides/explainshell/<p>Bash commands frequently have need many additional options to do exactly what you need. If you have ever seen a command recommended on an internet site like <a href="https://serverfault.com">https://serverfault.com</a> they often don’t explain all the options they use.</p>
<p>You could use the man page to check them all but nobody’s got time for that.</p>
<p>In stead use <a href="https://explainshell.com">https://explainshell.com</a>. Just dump the command along with all the options into the search bar and you’ll get it all nicely explained.</p>How To Speed Up Find With -exec Many Times
https://bash-prompt.net/guides/bash-find-exec-speedup/
Sat, 20 Feb 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-find-exec-speedup/<p>We all use <a href="https://www.gnu.org/software/findutils/find">find</a> to locate stuff on the command line. The <code>-exec</code> option allows us to execute a command on the located objects without having to pipe the output anywhere.</p>
<p>This is convenient but slow.</p>
<p>Find executes the command for every matched file. For example, the following command runs <code>ls -la</code> individually for every file in the <code>/home/user/Documents/</code> directory:</p>
<pre tabindex="0"><code>find /home/user/Documents/ -type f -exec ls -ls {} \;
</code></pre><p>This command takes <strong>9.5s</strong> on the my Documents directory. That’s pretty slow for the 3763 files that are in my Documents directory.</p>How To Quickly Find The Number Of CPU Cores
https://bash-prompt.net/guides/bash-number-of-processors/
Fri, 19 Feb 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-number-of-processors/<p>Sometimes you need to determine how many CPU cores a system has. This might be when you’re running <a href="https://www.gnu.org/software/make/">make</a> to use some or all of your CPU cores or some compression tools that take a CPU cores argument.</p>
<p>If you’re not trying to find this number in a script you can <code>grep</code> the contents of <code>/proc/cpuinfo</code>:</p>
<pre tabindex="0"><code>cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
</code></pre><p>Or you could open <code>top</code> and press <strong>1</strong> which will list all your CPU cores individually:</p>How To Terminate A Stalled SSH Connection
https://bash-prompt.net/guides/bash-ssh-kill-dead-connectin/
Fri, 12 Feb 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-ssh-kill-dead-connectin/<p>If you have to work of SSH with a flaky network connection you will have been left with an SSH terminal open to the remote server that is stalled or unresponsive. It will not accept any key presses but isn’t closed either.</p>
<p>I used to think that the only fix was to close the terminal window and SSH in again.</p>
<p>This isn’t the only option as SSH comes with some escape sequences. One of which is to terminate the current connection.</p>The SSH KeyGen Security Option You Probably Aren't Using
https://bash-prompt.net/guides/bash-ssh-unused-option/
Sat, 23 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-ssh-unused-option/<p>Everyone knows how to generate a new SSH key:</p>
<pre tabindex="0"><code>ssh-keygen -t ed25519
</code></pre><p>(you really should be using ed25519 if your environment supports it).</p>
<p>What most people don’t realize is that you can make your private key more robust against brute forcing if an unauthorized party gets access to it with a single additional option.</p>
<p>That option is the <code>-a <NUMBER></code> option. This option tells <code>ssh-keygen</code> to use the number specified of <strong>K</strong>ey <strong>D</strong>erivation <strong>R</strong>ounds to use when generating the key. E.g.:</p>Some Useful Bash Top Settings
https://bash-prompt.net/guides/bash-top-usefull-stuff/
Fri, 22 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-top-usefull-stuff/<p>There are lots of terminal based real-time system reporting tools such as <a href="https://nicolargo.github.io/glances/">glances</a> and <a href="https://htop.dev/">htop</a> that are prettier than classic <code>top</code>.</p>
<p>However, sometimes you find yourself on systems that don’t have <code>glances</code> or <code>htop</code> installed so you’ve got to use <code>top</code>. These tips will make top’s output a bit more useful.</p>
<h2 id="show-cpu-cores-individually">Show CPU cores individually</h2>
<p>The default output for <code>top</code> is to summarize the system load of all cores. Here’s my laptop:</p>A Simple Command Line CPU Benchmark
https://bash-prompt.net/guides/bash-simple-bash-benchmark/
Thu, 21 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-simple-bash-benchmark/<p>I use a lot of virtual machines from a number of providers. They usually list them as <strong>1 vCPU</strong> which doesn’t give much indication of how much processing power that single core is giving you.</p>
<p>There are lots of fully-featured benchmarking utilities that you could install to get a very details insight of how your CPU performs.</p>
<p>Ain’t nobody got time for that.</p>
<p>Instead, I use the following dead simple single core benchmark. It times how long the system takes to sha312sum 10GB of zeros:</p>How To Copy A File Using Netcat
https://bash-prompt.net/guides/bash-netcat-copy-file/
Tue, 12 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-netcat-copy-file/<p>When you copy a file from one Linux server to another you’re first choice will be SSH. SSH is secure and ubiquitous and <strong>should</strong> be your first choice.</p>
<p>Sometimes the CPU overhead of SSH’s encryption can be the bottle neck on transfer speed. This handicap can be significant if you are copying huge amounts of data.</p>
<p>One way to avoid this is to use <a href="http://netcat.sourceforge.net/">netcat</a>.</p>
<p>Netcat allows you to move data between systems without using any encryption maximizing your transfer speed.</p>Intelligent Console History Search
https://bash-prompt.net/guides/bash-fancy-history/
Sat, 09 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/bash-fancy-history/<p>Everyone knows, or should know, that typing <strong>CTRL+R</strong> on the command line and typing something will perform a reverse search through your command history.</p>
<p>This system can be improved upon.</p>
<p>With the code shown below you can start typing on the command line then hit the up-arrow to match the last instance in yoru history of what you have’ve written. Pressing the up-arrow again will print the match after the first and so on.</p>How To Block Pinterest Search Results in Google Images
https://bash-prompt.net/guides/pinterest-ublockorigin/
Tue, 05 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/pinterest-ublockorigin/<p>Do you hate getting Pinterest results when you’re using Google Images?</p>
<p>I know I do.</p>
<p>There is a simple <a href="https://ublockorigin.com/">uBlock Origin</a> filter that will stop you ever seeing those results again.</p>
<p>First, you need to install the uBlock Origin plugin for your browser. In fact, install it on all your browsers. Load <a href="https://www.mozilla.org/en-US/firefox/">Firefox</a> on your mobile phone and use it there too.</p>
<p>After, you’ve installed uBlock Origin (make sure you install <strong>uBlock Origin</strong>, both words) go to the settings and find the <strong>My filters</strong> section. Then copy and paste the following lines:</p>How To Create Custom Share Links With NextCloud
https://bash-prompt.net/guides/nextcloud-share-redirect/
Sat, 02 Jan 2021 00:00:00 +0000https://bash-prompt.net/guides/nextcloud-share-redirect/<p>I run a NextCloud instance and one of the little paper cuts that bug me is that I can’t create a custom link to a publicly accessible folder.</p>
<p>When a shared folder is created in the NextCloud file manager a random URL is created that has the following form:</p>
<pre tabindex="0"><code>https://example.comm/index.php/s/catTLcZxBbgSjXA
</code></pre><p>This is not easy to remember when I want to give out a link to a file I want to share.</p>How To Download Files From URLs With Redirects
https://bash-prompt.net/guides/bash-curl-follow-redirects/
Mon, 28 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-curl-follow-redirects/<p>It’s a very common task to need to download a file on the command line of a remote server. This is fine when the URL is a direct link to a file. However, often things get annoying and the download link has some PHP that redirects to the actual location of the file e.g.:</p>
<pre tabindex="0"><code>https://www.process-one.net/downloads/downloads-action.php?file=/20.12/ejabberd_20.12-0_amd64.deb
</code></pre><p>Fortunately, <a href="https://curl.se/">cURL</a> can help you here. All you need to do is use it as follows:</p>
<pre tabindex="0"><code>curl -L <URL> -o <OUTFILE>
</code></pre><p>Using the example URL gives us:</p>The Best Way To Copy Lots Of Small Files
https://bash-prompt.net/guides/bash-rsync-speedup/
Sat, 19 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-rsync-speedup/<p>Copying lots of small files from one Linux host to another can take a long time. Much longer than the data alone should take to copy.</p>
<p>I’ve often wondered, when I’ve had to copy lots of files what is the fastest way to do this.</p>
<p>Let’s find out!</p>
<h2 id="the-setup">The Setup</h2>
<p>To start theist tests I created 100K 64b files of random data all contained in a directory called <code>100k</code>.
This directory was 825M.</p>How to find which systemd unit owns a process
https://bash-prompt.net/guides/bash-systemd-process/
Fri, 18 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-systemd-process/<p>I was refering the the <code>systemctl</code> man page checking on <code>systemctl status</code> when I saw this:</p>
<pre tabindex="0"><code>status [PATTERN...|PID...]]
</code></pre><p>That’s right, you can use <code>systemctl status <PID></code> and it will give you information about that process if it was started by systemd, what unit started it along with status information of that unit.</p>
<p>Here’s the example output for a process on this server:</p>
<pre tabindex="0"><code># systemctl status 6555
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-12-18 11:06:57 UTC; 4h 23min ago
Docs: man:nginx(8)
Process: 6549 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SU
Process: 6552 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 6553 (nginx)
Tasks: 2 (limit: 1149)
Memory: 22.3M
CGroup: /system.slice/nginx.service
├─6553 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─6555 nginx: worker process
Dec 18 11:06:57 web-1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 18 11:06:57 web-1 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argume
Dec 18 11:06:57 web-1 systemd[1]: Started A high performance web server and a reverse proxy server.
</code></pre><p>This tells you that the process was loaded from <code>nginx.service</code> along with a bunch more status information on <code>nginx.service</code>.</p>Benchmarking SSH Ciphers
https://bash-prompt.net/guides/bash-ssh-ciphers/
Thu, 17 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-ssh-ciphers/<p>Whenever I’ve got a lot of data to transfer I usually kick off the <code>rsync</code> or <code>scp</code> with the default <code>SSH</code> settings and then, after an hour or so, wonder if I could have sped things up with a different cipher.</p>
<p>So I decided to find out now for my future self and maybe save some time.</p>
<h2 id="a-quick-not-about-ssh-ciphers">A quick not about SSH Ciphers</h2>
<p>SSH uses several ciphers and algorithms. I have encountered lots of sysadmins that think their choice of SSH key determines their transfer speed. SSH keys are only used by SSH to transmit the shared key that is used for the symmetric cipher which encrypts all of the session data. The admins SSH key does not affect the transfer speed only the choide symmetric cipher does.</p>A Short Guide To Using A Yubikey For SSH Authentication
https://bash-prompt.net/guides/bash-ssh-yubikey/
Fri, 11 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-ssh-yubikey/<p><a href="http://www.openssh.com/">SSH</a> is the default method for systems administrators to log into remote Linux systems. Traditionally, [SSH keys] are secured with a password. This situation can be improved upon by enforcing a second authentication factor - a <a href="https://www.yubico.com/">Yubikey</a>.</p>
<p>After you do this then only someone with <strong>both</strong> the password and the Yubikey will be able to use the SSH key pair to log into your Linux system.</p>
<p>This guide is a quick start to using a Yubikey with SSH.</p>How To Use Varnish As A Highly Available Load Balancer On CentOS 8 With SSL
https://bash-prompt.net/guides/varnish-loadbalancer-centos-8/
Mon, 07 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/varnish-loadbalancer-centos-8/<p>Load balancing with high availability can be tough to set up. Fortunately, <a href="https://varnish-cache.org/">Varnish HTTP Cache</a> server provides a dead simple highly available load balancer that will also work as a caching server.</p>
<p>The modern use of SSL/TLS for all traffic has made this a little harder as Vanish has to handle unencrypted traffic to cache it. This means that we will need to terminate and decrypt the HTTPS connections before they are handed off to Varnish.</p>How To Use Varnish As A Highly Available Load Balancer On Debian 10 With SSL
https://bash-prompt.net/guides/varnish-loadbalancer-debian-10/
Mon, 07 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/varnish-loadbalancer-debian-10/<p>Load balancing with high availability can be tough to set up. Fortunately, <a href="https://varnish-cache.org/">Varnish HTTP Cache</a> server provides a dead simple highly available load balancer that will also work as a caching server.</p>
<p>The modern use of SSL/TLS for all traffic has made this a little harder as Vanish has to handle unencrypted traffic to cache it. This means that we will need to terminate and decrypt the HTTPS connections before they are handed off to Varnish.</p>How To Use Varnish As A Highly Available Load Balancer On Ubuntu 20.04 With SSL
https://bash-prompt.net/guides/varnish-loadbalancer-ubuntu-20-04/
Mon, 07 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/varnish-loadbalancer-ubuntu-20-04/<p>Load balancing with high availability can be tough to set up. Fortunately, <a href="https://varnish-cache.org/">Varnish HTTP Cache</a> server provides a dead simple highly available load balancer that will also work as a caching server.</p>
<p>The modern use of SSL/TLS for all traffic has made this a little harder as Vanish has to handle unencrypted traffic to cache it. This means that we will need to terminate and decrypt the HTTPS connections before they are handed off to Varnish.
We will do this with Apache2.</p>A Short Guide To Using Linux Man Pages
https://bash-prompt.net/guides/bash-man-guide/
Sat, 05 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-man-guide/<p>Linux man pages remain the best source of information for using Linux command line tools. You don’t need an internet connection to instantly get a description of how a utility works and an explanation of all of it’s flags, options and syntax.</p>
<p>Using a man page is as simple as running:</p>
<pre tabindex="0"><code>man <COMMAND>
</code></pre><p>The problem is that quickly parsing all the information is difficult. These tips will make your life more efficient whenever you turn to man for information.</p>How To Colorize Man Pages
https://bash-prompt.net/guides/bash-colorize-man/
Sat, 05 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-colorize-man/<p>Man pages are <strong>the</strong> canonical source of information for all the commands that you run on your Linux command line. By default, man pages are not colorized, this makes them a little harder to quickly parse for information.</p>
<p>This quick edit to your <code>.bashrc</code> file adds some syntax highlighting to your man pages. All you need to do is to copy and past the following into your <code>.bashrc</code> file:</p>
<pre tabindex="0"><code>man() {
env \
LESS_TERMCAP_mb="$(printf "\e[1;31m")" \
LESS_TERMCAP_md="$(printf "\e[1;31m")" \
LESS_TERMCAP_me="$(printf "\e[0m")" \
LESS_TERMCAP_se="$(printf "\e[0m")" \
LESS_TERMCAP_so="$(printf "\e[1;44;33m")" \
LESS_TERMCAP_ue="$(printf "\e[0m")" \
LESS_TERMCAP_us="$(printf "\e[1;32m")" \
man "${@}"
}
</code></pre><p>After you’ve edited your <code>.bashrc</code> you can use the new configuration by either opening a new terminal or reload the environment of your current one with the following command:</p>How To Enable Brotli Compression In Apache 2.4 on CentOS 8
https://bash-prompt.net/guides/apache-brotli-centos-8/
Sat, 05 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/apache-brotli-centos-8/<p>Web servers have been able to compress the content they serve for quite a while now. When they receive a request for an asset that lends itself to compression, usually a text file such as HTML or CSS it will compress it before sending it to the browser. The browser will then decompress the file and load it. This process cuts down on the amount of data that is served and also speeds up website loading.</p>How To Enable Brotli Compression In Apache 2.4 on Debian 10
https://bash-prompt.net/guides/apache-brotli-debian-10/
Sat, 05 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/apache-brotli-debian-10/<p>Web servers have been able to compress the content they serve for quite a while now. When they receive a request for an asset that lends itself to compression, usually a text file such as HTML or CSS it will compress it before sending it to the browser. The browser will then decompress the file and load it. This process cuts down on the amount of data that is served and also speeds up website loading.</p>How To Enable Brotli Compression In Apache 2.4 on Ubuntu 20.04
https://bash-prompt.net/guides/apache-brotli-ubuntu-2004/
Sat, 05 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/apache-brotli-ubuntu-2004/<p>Web servers have been able to compress the content they serve for quite a while now. When they receive a request for an asset that lends itself to compression, usually a text file such as HTML or CSS it will compress it before sending it to the browser. The browser will then decompress the file and load it. This process cuts down on the amount of data that is served and also speeds up website loading.</p>How To Enable Static Brotli Compression In Apache 2.4
https://bash-prompt.net/guides/apache-brotli-static/
Sat, 05 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/apache-brotli-static/<p>Web servers have been able to compress the content they serve for quite a while now. When they receive a request for an asset that lends itself to compression, usually a text file such as HTML or CSS it will compress it before sending it to the browser. The browser will then decompress the file and load it. This process cuts down on the amount of data that is served and also speeds up website loading.</p>How To Find Which Repository A Package Is From On Debian and Ubuntu
https://bash-prompt.net/guides/bash-apt-policy/
Fri, 04 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-apt-policy/<p>I recently had to find which repository held the <code>nginx</code> package so I could enable the corresponding <code>deb-src</code> line in order to build the source code with <code>apt</code>.</p>
<p>There are two ways to get this information. The first is with <code>apt show <PACKAGE></code> e.g.:</p>
<pre tabindex="0"><code>apt show nginx
</code></pre><p>Then search for the line that begins <code>APT-Sources:</code></p>
<pre tabindex="0"><code>APT-Sources: http://mirrors.digitalocean.com/ubuntu focal-updates/main amd64 Packages
</code></pre><p>Alternatively, can get the same information by using <code>apt policy</code>:</p>
<pre tabindex="0"><code># apt policy nginx
nginx:
Installed: (none)
Candidate: 1.18.0-0ubuntu1
Version table:
1.18.0-0ubuntu1 500
500 http://mirrors.digitalocean.com/ubuntu focal-updates/main amd64 Packages
1.17.10-0ubuntu1 500
500 http://mirrors.digitalocean.com/ubuntu focal/main amd64 Packages
</code></pre><p>Both of these commands tell us that correct repository line in <code>sources.list</code> contains this <code>http://mirrors.digitalocean.com/ubuntu focal-updates/main</code> information.</p>How To Install Brotli For NGINX Open Source On CentOS 8
https://bash-prompt.net/guides/nginx-brotli-cento-8/
Fri, 04 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/nginx-brotli-cento-8/<p><a href="https://github.com/google/brotli">Brotli</a> is a high-performance, lossless compression algorithm developed and maintained by Google. It can be use by webservers to compress files like <code>.html</code> and <code>.css</code> files and increase the perforce of websites and reduce their bandwidth requirements.</p>
<p><a href="https://www.nginx.com/">NGINX</a> does not provide support for a brotli module for their open source version. This means that you will need to compile the NGINX with brotli support along with the brotli module.</p>
<h2 id="build-nginx-with-brotli">Build NGINX with brotli</h2>
<p>First, install all the packages that will be needed:</p>How To Install Brotli For NGINX Open Source On Debian 10
https://bash-prompt.net/guides/nginx-brotli-debian-10/
Fri, 04 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/nginx-brotli-debian-10/<p><a href="https://github.com/google/brotli">Brotli</a> is a high-performance, lossless compression algorithm developed and maintained by Google. It can be use by webservers to compress files like <code>.html</code> and <code>.css</code> files and increase the perforce of websites and reduce their bandwidth requirements.</p>
<p><a href="https://www.nginx.com/">NGINX</a> does not provide support for a brotli module for their open source version. This means that you will need to compile the NGINX with brotli support along with the brotli module.</p>
<h2 id="build-nginx-with-brotli">Build NGINX with brotli</h2>
<p>First, install all the packages that will be needed:</p>How To Install Brotli For NGINX Open Source On Ubuntu 20.04
https://bash-prompt.net/guides/nginx-brotli-ubuntu-20.04/
Fri, 04 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/nginx-brotli-ubuntu-20.04/<p><a href="https://github.com/google/brotli">Brotli</a> is a high-performance, lossless compression algorithm developed and maintained by Google. It can be use by webservers to compress files like <code>.html</code> and <code>.css</code> files and increase the perforce of websites and reduce their bandwidth requirements.</p>
<p><a href="https://www.nginx.com/">NGINX</a> does not provide a compiled brotli module for their open source version. This means that you will need to compile the NGINX brotli module from source.</p>
<h2 id="build-nginx-with-brotli">Build NGINX with brotli</h2>
<p>First, log into your Ubuntu server and install all the build packages that you will need:</p>How To Write To A Network Socket With Bash
https://bash-prompt.net/guides/bash-sockets/
Thu, 03 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-sockets/<p>You probably didn’t know but you can trivially open a network socket and communicate with a host by writing to:</p>
<pre tabindex="0"><code>/dev/<PROTO>/<HOST>/<PORT>
</code></pre><p>The protocol can be UDP or TCP and the host any internet connect machine including <code>localhost</code>.</p>
<p>Why is this useful?</p>
<p>It allows you to create scripts that, for example, grab a webpage and don’t rely on external tools like <code>curl</code> or <code>telnet</code>. This makes the scrip much more portable and you don’t need to run bunch of test to make sure your dependancies are present on the system.</p>How To Measure You Current Laptop Battery Capacity vs New
https://bash-prompt.net/guides/bash-battery-upower-capacity/
Tue, 01 Dec 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-battery-upower-capacity/<p>All rechargeable batteries degrade over time. If you’ve ever wondered how your laptop’s battery is holding up this simple command will tell you how you can get some information.</p>
<p>Run the following command:</p>
<pre tabindex="0"><code>$ upower -d
</code></pre><p>And look for the following line:</p>
<pre tabindex="0"><code>capacity: 73.7304%
</code></pre><p>As you can see my laptop’s battery holds 26% less power than it did when it rolled off the assembly line.</p>
<p>When the charger is back in you can also find the time until it’s fully charged again.</p>How To Encrypt A File With OpenSSL
https://bash-prompt.net/guides/bash-openssl-encrypt/
Sun, 29 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-openssl-encrypt/<p><a href="https://gnupg.org/">GPG</a> is the fist utilty that most admins think of when they need to encrypt some data at reast. However, it is not very simple to quickly encrypt a file with a password.</p>
<p><a href="https://wiki.openssl.org/index.php/Enc">OpenSSL</a> makes this much easier.</p>
<p>The following command will encrypt a file:</p>
<pre tabindex="0"><code>$ openssl enc -aes-256-cbc -salt -in <FILE> -out <ENCRYPTED-FILE>
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
</code></pre><p>Unencrypt the file with the folloing command:</p>Comparing The Encryption Speed of GPG vs OpenSSL
https://bash-prompt.net/guides/bash-gpg-v-ssl/
Sat, 28 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-gpg-v-ssl/<p>Encrypting data at rest is a modern requirement that occurs all the time. The go-to method that most admins think of is to use <a href="https://gnupg.org/">GPG</a>.</p>
<p>But it’s slow.</p>
<p>How slow? Lets find out.</p>
<p>First, I generated a 1GB file of random data:</p>
<pre tabindex="0"><code>dd if=/dev/urandom of=data.file bs=1MB count=1024
</code></pre><p>Then I timed its encryption with GPG:</p>
<pre tabindex="0"><code>gpg --encrypt --compress-level 0 --sign --armor -r [email protected] data.file
Time: 0m13.285s
</code></pre><p>The <code>--compress-level 0</code> disables compression as there is no compression used by OpenSSL.</p>Benchmark Your Linux Bitcoin or LiteCoin Mining Rig With BFGMiner
https://bash-prompt.net/guides/benchmarking-cyptocurrency-mining-with-bfgminer/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/benchmarking-cyptocurrency-mining-with-bfgminer/<p>Once you have decided that you want to start mining cryptocurrency you need to work out how fast your mining rig crunch work blocks and earn you crypto coins. Working out how fast your rig is called benchmarking. We will use the <a href="http://bfgminer.org/">BFGMiner</a> coin mining tool to benchmark your system.</p>
<p>BFGMiner is a crypto coin mining utility that includes a benchmark mode. In this mode, it will tell you how many hashes per second your rig can computer. This number is very big so is abbreviated as follows:</p>How to Calculate The Profit of Mining Bitcoin BTC
https://bash-prompt.net/guides/calculate-bitcoin-profit/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/calculate-bitcoin-profit/<p>So you’ve got a system that you want to try mining some Bitcoins (BTC). The first question you’re going to as is “Will it make any money?”.</p>
<p>That’s a great first question and one that’s pretty easy to answer. All you need is two pieces of information and you can get a quick (rough) answer. This information is:</p>
<ol>
<li>How quickly can the system generate cryptocurrency?</li>
<li>How much electricity does my system use to do it?</li>
</ol>
<p>Once you have that information you can use the excellent mining calculator at <a href="https://www.cryptocompare.com/mining/calculator/">Cryptcompare</a> to do the math using the current market values to give you an answer.</p>How to Calculate The Profit of Mining BitcoinCash BCH
https://bash-prompt.net/guides/calculate-bitcoincash-profit/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/calculate-bitcoincash-profit/<p>So you’ve got a system that you want to try mining some <a href="https://www.bitcoincash.org/">BitcoinCash</a> (BCH). The first question you’re going to as is “Will it make any money?”.</p>
<p>That’s a great first question and one that’s pretty easy to answer. All you need is two pieces of information and you can get a quick (rough) answer. This information is:</p>
<ol>
<li>How quickly can the system generate cryptocurrency?</li>
<li>How much electricity does my system use to do it?</li>
</ol>
<p>Once you have that information you can use the excellent Dodgecoin mining profit calculator at <a href="https://www.coinwarz.com/mining/bitcoincash/calculator">https://www.coinwarz.com</a> to do the math using the current market values to give you an answer.</p>How to Calculate The Profit of Mining Dodgecoin DOGE
https://bash-prompt.net/guides/calculate-dodgecoin-profit/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/calculate-dodgecoin-profit/<p>So you’ve got a system that you want to try mining some <a href="https://dogecoin.com/">Dodgecoins</a> (DOGE). The first question you’re going to as is “Will it make any money?”.</p>
<p>That’s a great first question and one that’s pretty easy to answer. All you need is two pieces of information and you can get a quick (rough) answer. This information is:</p>
<ol>
<li>How quickly can the system generate cryptocurrency?</li>
<li>How much electricity does my system use to do it?</li>
</ol>
<p>Once you have that information you can use the excellent Dodgecoin mining profit calculator at <a href="https://www.coinwarz.com/mining/dogecoin/calculator">https://www.coinwarz.com</a> to do the math using the current market values to give you an answer.</p>How to Calculate The Profit of Mining Litecoin LTC
https://bash-prompt.net/guides/calculate-litecoin-profit/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/calculate-litecoin-profit/<p>So you’ve got a system that you want to try mining some <a href="https://litecoin.com">Litecoin</a>. The first question you’re going to as is “Will it make any money?”.</p>
<p>That’s a great first question and one that’s pretty easy to answer. All you need is two pieces of information and you can get a quick (rough) answer. This information is:</p>
<ol>
<li>How quickly can the system generate cryptocurrency?</li>
<li>How much electricity does my system use to do it?</li>
</ol>
<p>Once you have that information you can use the excellent mining calculator at <a href="https://www.cryptocompare.com/mining/calculator/">Cryptcompare</a> to do the math using the current market values to give you an answer.</p>How To Calculate The Profit of Mining Monero XRM With Minergate
https://bash-prompt.net/guides/minergate-monero-evaluator/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/minergate-monero-evaluator/<p>You’ve got a computer, it’s running Linux and you want to try mining some <a href="https://www.getmonero.org/">Monero</a>. Before you commit to running the system at 100% for a few weeks to see if you can make any money you should run a quick evaluation and see how much Monero the system can mine.</p>
<p><a href="https://minergate.com/">Minergate</a> provides a mining client that gives you a simple readout of how many hashes-per-second your system can crunch whilst it is mining and use that to work out your profit.</p>How To Get A Cheap AWS GPU Spot Instance
https://bash-prompt.net/guides/aws-gpu-spot/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/aws-gpu-spot/<h2 id="introduction">Introduction</h2>
<p>Before you can start mining cryptocurrency you need a GPU rocking rig to do all the hard work. <a href="https://aws.amazon.com/">Amazon AWS</a> is the world leader in providing computing resources on demand. Normally, spinning up a GPU enabled rig to use for mining is going to get expensive. Fortunately, AWS provide <a href="https://aws.amazon.com/ec2/spot/">spot</a> instances at a <strong>70-90%</strong> discount.</p>
<p>These instances are so cheap because they can, and will, go away with only a few minute’s notice. Spot instances let Amazon rent out unused computing capacity that they will reallocate to full paying customers when they request it. This arrangement suits crypto mining well because mining happens in small chunks so losing a few minute’s work is nothing against the <strong>90%</strong> saving.</p>How To Quickly Evaluate A Computer For Crypto-Mining Profit With Minergate
https://bash-prompt.net/guides/minergate-calculator/
Mon, 23 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/minergate-calculator/<p>The toughest part of deciding to mine cryptocurrency is trying to work out if the system you have access can make any profit. In this guide we’ll take a look at how to evaluate a remote Linux server and see if you can make any money using the <a href="https://minergate.com">Minergate GUI</a>.</p>
<p>The remote server that I’m going to use is the following AWS GPU server:</p>
<p>AWS <strong>g4dn.xlarge</strong> instance:</p>
<ul>
<li>4 x VCPU (Xeon)</li>
<li>1 NVIDIA K80 GPU</li>
<li>16GB RAM</li>
<li>1 x NVIDIA T4 GPU</li>
<li>$0.15 per hour (spot instance pricing)</li>
</ul>
<p>Next, I needed to find out how good they are at mining cryptocurrency and work out if they are able to make a profit i.e. generate more cryptocurrency than either the electricity consumption in the case of my laptop or the monthly rental in the case of the cloud machines needs.</p>How To Create A Fast Encrypted Tunnel For Firefox Using SSH
https://bash-prompt.net/guides/ssh-firefox-tunnel/
Thu, 19 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/ssh-firefox-tunnel/<p>VPN’s are great. I moved to Wireguard a while ago and I haven’t looked back. However, sometimes, especially on my laptop, I need a quick VPN. This is the fastest solution I’ve found.</p>
<p>It uses SSH to create an encrypted tunnel and also creates a local <a href="https://en.wikipedia.org/wiki/SOCKS">SOCKS</a> server. You then configure Firefox to direct all requests to the SOCKS server on localhost that are directed down the tunnel where they exit and travel on to the destination web server.</p>A Simple Command Line Stopwatch
https://bash-prompt.net/guides/bash-stopwatch/
Sat, 14 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-stopwatch/<p>Have you never needed to time something and only had access to a terminal? No, well it’s fun anyway.</p>
<p>You can start the stopwatch with this command:</p>
<pre tabindex="0"><code>time read
</code></pre><p>And stop it with <strong>CTRL+C</strong>.</p>
<p>It’s one of those commands that is useless right up until that time when it’s <strong>exactly</strong> what you need.</p>Speed Up Your SSH Connections
https://bash-prompt.net/guides/ssh-keep-socket/
Fri, 13 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/ssh-keep-socket/<p>SSH’ing into a server takes a few seconds. This doesn’t seem like much but when your logging into and out of servers all day removing those seconds makes life a little easier.</p>
<p>The following configuration will create a master connection where all the crypto negation and key exchange takes place. This master connection can then be reused for any subsequent connection meaning that the connections are near instant.</p>
<p>Put the following configuration into your SSH config file at <code>~/.ssh/config</code>:</p>Empty A File But Retain Permissions and Ownerships
https://bash-prompt.net/guides/bash-dev-null/
Mon, 09 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-dev-null/<p>Sometimes, especially with huge log files, you need to delete all the data in a file without getting rid of it.</p>
<p>You could just use <code>rm</code> and then <code>touch</code> to re-create the file. The problem is that I inevitably forget to look at the ownerships and and permissions on the file until after I delete it.</p>
<p>Instead of <code>rm</code> copy <code>/dev/null</code> to the file instead. This will zero its contents but keep the file and all of its meta data like its permissions and ownerships.</p>How To Use rev In Your Bash Fu
https://bash-prompt.net/guides/bash-rev/
Mon, 09 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/bash-rev/<p>A common problem when you’re writing bash scripts or creating one liners is to get something from the end of some text. That could be last N characters, the last word etc etc.</p>
<p>There are a number of ways to do this like without using <code>rev</code> but you will need to remember the unique method for each problem. For example, take the following line:</p>
<pre tabindex="0"><code>one.two.three.four.five
</code></pre><p>Say you want to extract the <strong>five</strong> from the end of the line. The problem is that you need to grab the last word from lines that have different number of different words. This can get complicated.</p>How To List Your Hardware On Linux With Inxi
https://bash-prompt.net/guides/inxii/
Sat, 07 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/inxii/<p>Getting a concise and informative list of all the hardware components on your system can be hard. The standard tool is <a href="https://github.com/lyonel/lshw">lshw</a>. This is a great tool but it’s output can be very verbose.</p>
<p>I recently discovered a different tool that a really terrific job of showing you your hardware information:</p>
<p><a href="https://github.com/smxi/inxi">inxi</a></p>
<p>The feature I particularly like is that it prints the drive that each piece of hardware is using.</p>
<p>Use it with the following options to get a list of all your hardware:</p>How To Pre-Compress Your Website With Gzip On Debian 10 And Apache2
https://bash-prompt.net/guides/apache2-mod-precompress/
Thu, 05 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/apache2-mod-precompress/<p>Whenever you visit a website you will almost certainly recieve compressed <code>.html</code>, <code>.css</code>, <code>.js</code> and <code>.xml</code> files. This because they are very compressible, over 90%, which saves bandwidth and speeds up load times.</p>
<p>However, they’re compressed by the webserver every time they are served. This is a waste of CPU cycles and places extra load on both the webserver and the client. The anser is to compress all of these files once on the server and serve the pre-compressed files.</p>How To Pre-CompressYour Website With Brotli On Debian 10 And NGINX
https://bash-prompt.net/guides/nginx-brotli-precompressed/
Thu, 05 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/nginx-brotli-precompressed/<p>If you have followed <a href="https://bash-prompt.net/guides/nginx-brotli/">my guide</a> for enabling brotli compression with NGINX then your server is already serving your content with brotli compression.</p>
<p>The only downside to this is that NGINX compresses the files every time it serves them. A feature of the brotli module is that it can serve files that have already been compressed with brotli. This means that they you only have to compress them once saving your CPU from doing repete work.</p>Protect Your Site With Apache2 Mod Defensible
https://bash-prompt.net/guides/how-to-install-apache2-mod-defensible/
Thu, 05 Nov 2020 00:00:00 +0000https://bash-prompt.net/guides/how-to-install-apache2-mod-defensible/<p>If you have a website on your Debian 10 server you are probably thinking of how you can protect it. There are many tools that you can deploy but there is an Apache2 module that you can install, configure and use in a couple of minutes:</p>
<p>libapache2-mod-defensible</p>
<p>This module will lookup the originating IP of any incoming web request and block it if it’s known as an IP engaging in malicious or illegal behavior.</p>X11 Application Forwarding Made Easy
https://bash-prompt.net/guides/x11-forwarding-the-easy-way/
Wed, 30 Sep 2020 00:00:00 +0000https://bash-prompt.net/guides/x11-forwarding-the-easy-way/<p>I recently needed to run a GUI application on a remote, headless Linux server. I went down the usual road of trying to get X11 forwarding to work and met the usual slew of errors.</p>
<p>Then I found <a href="https://xpra.org/">Xpra</a>.</p>
<p>Save yourself the pain and go straight to Xpra if you need to display an application on your laptop that is running on a remote Linux system.</p>
<h2 id="what-does-xpra-do">What Does Xpra Do?</h2>
<p>Xpra allows you to run a program that has a GUI output on a remote Linux server. This means that they program is running remotely but the GUI is displayed locally on your Laptop.</p>How To Get A Remote Desktop A Headless Server
https://bash-prompt.net/guides/vnc-server/
Thu, 20 Aug 2020 00:00:00 +0000https://bash-prompt.net/guides/vnc-server/<p>I recently needed to run an application that was GUI only on a remote, headless server. After I messed with X-Forwarding for long enough to get <strong>really</strong> frustrated (which wasn’t long) I figured out how to get a desktop running running that I could log into and run the app.</p>
<p>Here’s how.</p>
<p>First, SSH into your server and install the <a href="https://tightvnc.com/">tightVNC</a> server and the <a href="https://xfce.org/">Xfce</a> desktop. On Ubuntu 20.03 and Debian 10 the following command will install these for you:</p>How To Use GNU Parallel To Create A Supercomputer
https://bash-prompt.net/guides/gnu-parallel-multi-server/
Tue, 07 Jul 2020 00:00:00 +0000https://bash-prompt.net/guides/gnu-parallel-multi-server/<p>I’ve written about <a href="https://www.gnu.org/software/parallel/">GNU Parallel</a> in a <a href="https://bash-prompt.net/guides/parallell-bash/">previous post</a> because it’s a really amazing tool. Well, it’s even more amazing than I thought.</p>
<p>Parallel has the built-in ability to send jobs to remote servers, use all of their cores to work on something, and return the results to the current, local directory.</p>
<p>The easiest way to get a handle on how this works is to walk through an example. I’m going to use two remote servers to compress some files. The remote servers are:</p>Using lsof To Discover What Ports Are In Use
https://bash-prompt.net/guides/lsof/
Fri, 03 Jul 2020 00:00:00 +0000https://bash-prompt.net/guides/lsof/<p>A task that comes up often enough that you need to memorize a command and it’s options is to find out what’s listening on a port. Sometimes it’s a result of seeing an error like <code>Address already in use</code> or <code>Socket in use</code> when you try to start a new network process. Or you might need to know what’s listening on what port to configure a firewall etc.</p>
<p>There are other tools that will show you the open network sockets such as <a href="https://ss64.com/bash/netstat.html">nestat</a> and <a href="https://ss64.com/bash/ss.html">ss</a> but I always find myself using <a href="https://ss64.com/bash/lsof.html">lsof</a>. The output is nicely formatted and informative.</p>How to automatically clear Pikaur's cache
https://bash-prompt.net/guides/pikaur-cache-flush/
Tue, 26 May 2020 00:00:00 +0000https://bash-prompt.net/guides/pikaur-cache-flush/<p>I’ve been using <a href="https://www.archlinux.org">Arch Linux</a> (btw) on my laptop for a while now and I’ve always used an <a href="https://wiki.archlinux.org/index.php/AUR_helpers">AUR helper</a> to automate finding, installing and updating AUR packages.</p>
<p>I started with <code>packer</code> and then moved on to <code>yaourt</code> when <code>packer</code>s development stopped. This also happened to <code>yaourt</code> so I started looking for another.</p>
<p>The <a href="https://aur.archlinux.org/packages/yay">yay</a> utility gets a lot of recommendations but it comes with a ~130MB Go dependency which put me off. So I kept looking.</p>How To Enable Brotli Compression In Apache 2.4
https://bash-prompt.net/guides/apache-brotoli/
Thu, 23 Apr 2020 00:00:00 +0000https://bash-prompt.net/guides/apache-brotoli/<p>Web servers have been able to compress the content they serve for quite a while now. When they receive a request for an asset that lends itself to compression, usually a text file such as HTML or CSS it will compress it before sending it to the browser. The browser will then decompress the file and load it. This process cuts down on the amount of data that is served and also speeds up website loading.</p>How to Use curl to Get HTTP Headers
https://bash-prompt.net/guides/get-headers-with-curl/
Mon, 20 Apr 2020 00:00:00 +0000https://bash-prompt.net/guides/get-headers-with-curl/<p>Configuring a webserver like <a href="https://nginx.org/">nginx</a> or <a href="https://httpd.apache.org/">Apache</a> is pretty simple to get a webpage served. Things can get trickier when you’re making configuration changes that are not visible when you check the page in a browser. These are changes like enabling GZIP compression or HTTP/2.</p>
<p>The page will look exactly the same if they are enabled or not. Sure, you can use a third-party site to evaluate your website but that always feels like cheating.</p>How to Stream Audio from Your Phone to Your Laptop
https://bash-prompt.net/guides/pulse-audio-bluetooth-streaming/
Tue, 14 Apr 2020 00:00:00 +0000https://bash-prompt.net/guides/pulse-audio-bluetooth-streaming/<p>These days your primary means of listening to music if likely from an app on your phone. So how do you get the music from your phone to your laptop or desktop that has better speakers?</p>
<p>The answer is to use Bluetooth and <a href="https://www.freedesktop.org/wiki/Software/PulseAudio/">PulseAudio</a>. PulseAudio is the modern sound implementation on the Linux desktop. It runs as a sound server and takes sound inputs such a microphone or your browser playing a YouTube video and directs this sound to outputs such as your Laptop’s speakers.</p>hdparm - A Simple Storage Benchmark
https://bash-prompt.net/guides/hdparm/
Tue, 31 Mar 2020 00:00:00 +0000https://bash-prompt.net/guides/hdparm/<p>Benchmarking is hard.</p>
<p>This article isn’t about creating traditional benchmark data because that’s hard. It’s much more work than my typical need which is, “Nice! A new laptop. I wonder how fast the disc[sic] is”. Yeah, I know, I haven’t had a hard disk in a laptop for a while but old habits die hard.</p>
<p>You have plenty of options for creating getting really nice benchmark info such as the excellent <a href="https://github.com/axboe/fio">fio</a> but if I have to read a man page and some internet guides then it isn’t what I’m looking for.</p>How to copy and paste into and out of a terminal
https://bash-prompt.net/guides/copy-paste-terminal/
Tue, 11 Feb 2020 00:00:00 +0000https://bash-prompt.net/guides/copy-paste-terminal/<h2 id="the-problem">The problem</h2>
<p>In the Linux desktop environment, there are two methods of copying and pasting. Highlight-to-copy/middle-click-to-paste and <code>CTRL+C</code>-to-copy/<code>CTRL+V</code>-to-paste. The highlighting copy/paste is easy to get text into and out of the terminal but <code>CTRL+C</code> is already mapped to a different function and <code>CTRL+V</code> doesn’t do anything.</p>
<p>This leads to the problem of not being able to copy/past text between applications and the terminal.</p>
<h2 id="the-solutions">The solutions</h2>
<h3 id="ctrlv-and-ctrl-v-in-the-terminal"><code>CTRL+V</code> and <code>CTRL-V</code> in the terminal.</h3>
<p>There <strong>are</strong> alternative shortcuts assigned to these functions in the terminal. You just need to press <code>SHIFT</code> at the same time as <code>CTRL</code>:</p>Benchmarking Magento Part 1 - Standard Install
https://bash-prompt.net/guides/magento-benchmark-1/
Mon, 03 Feb 2020 00:00:00 +0000https://bash-prompt.net/guides/magento-benchmark-1/<p>There are many options for improving the performance of an Magento installation but little benchmarking data regarding what sort of improvement they make. In this series of posts I will use a small virtual machine and test the some performance options to see which have the greatest impact on performance.</p>
<h2 id="the-setup">The Setup</h2>
<p>In this first post I am going to test a completely unmodified Magento installation using the sample data to provide the content. I am going to keep the specs of the machine I run Magento on as low as possible to see what can be achieved on limited hardware.</p>Benchmarking Magento Part 2 - PHP-FPM
https://bash-prompt.net/guides/magento-benchmark-2/
Mon, 03 Feb 2020 00:00:00 +0000https://bash-prompt.net/guides/magento-benchmark-2/<p><a href="https://php-fpm.org/">PHP-FPM</a> is a high performance alternative to the standard PHP library that I used in Part 1 of this series. Please see Part 1 for a run down of the configuration of the server that I am using in this series.</p>
<ul>
<li><a href="https://bash-prompt.net/guides/magento-benchmark-1">Part 1</a> - System setup and default configuration</li>
</ul>
<h2 id="installing-php-fpm">Installing PHP-FPM</h2>
<p>PHP-FPM is available from the default Debian repositories and is installed with the following command:</p>
<pre tabindex="0"><code>apt update
apt upgrade
apt install php-fpm
</code></pre><p>Next, configure Apache2 to use PHP-FPM:</p>Benchmarking Magento Part 3 - Reddis Cache
https://bash-prompt.net/guides/magento-benchmark-3/
Mon, 03 Feb 2020 00:00:00 +0000https://bash-prompt.net/guides/magento-benchmark-3/<p><a href="https://redis.io/topics/introduction">Redis</a> is an in-memory caching application that we will use to cache session information and as a full page cache. This post is <strong>Part 3</strong> of the Magento benchmarking series of posts. The server I am benchmarking here is the standard server used in Part 1 with PHP-FPM installed and configured from Part 2. You can see those posts here:</p>
<ul>
<li><a href="https://bash-prompt.net/guides/magento-benchmark-1">Part 1</a> System setup and default configuration</li>
<li><a href="https://bash-prompt.net/guides/magento-benchmark-2">Part 2</a> PHP-FPM</li>
</ul>
<h2 id="installing-redis">Installing Redis</h2>
<p>Redis is available from the default Debian repositories. Install it with the following commands:</p>How To Install Magento 2 on CentOS 8 in 10 minutes
https://bash-prompt.net/guides/magento-centos-8-10m/
Wed, 29 Jan 2020 00:00:00 +0000https://bash-prompt.net/guides/magento-centos-8-10m/<p>This guide will walk you through taking an brand new server to having a working Magento instance in 10 minutes or less. This guide follows all the recommended guidelines suggested by the Magento developers.</p>
<ol>
<li>A CentOS 8 server with at least 1GB for an archive based install or 2GB of RAM to use the Composer install.</li>
<li>Basic knowledge of using the Linux command line.</li>
<li>The hostname of your store must resolve (point) to the IP address of your server before you start this guide if you want to install an SSL certificate.</li>
<li>An account with Magento. Login or sign up <a href="https://account.magento.com">here</a>. You will need to get your Access Keys from your Magento account. See the Magento instructions <a href="https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html">here</a> on how to get those.</li>
</ol>
<p>In order to begin these steps, you must SSH into your server as a sudo enabled non-root user.</p>Benchmarking Magento Part 4 - Varnish Cache
https://bash-prompt.net/guides/magento-benchmark-4/
Sun, 24 Nov 2019 00:00:00 +0000https://bash-prompt.net/guides/magento-benchmark-4/<p><a href="https://varnish-cache.org/">Varnish</a> is an in-memory caching proxy server that caches website objects such as images, html pages, CSS files in RAM. Varnish works by accepting the web requests before Apache and serving an object very rapidly if it has it in its cache. If Varnish does not have the object then it will pass on the request to Apache.</p>
<p>This post is Part 4 of the Magento benchmarking series of posts. The server I am benchmarking here is the standard server used in Part 1 with PHP-FPM installed and configured from Part 2. You can see those posts here along with the Reddis cached server in Part 3:</p>How To Install Magento 2 on Ubuntu 18.04 LTS or Debian Buster in 10 minutes
https://bash-prompt.net/guides/install-magento-2-debian10-ubuntu8/
Wed, 30 Oct 2019 00:00:00 +0000https://bash-prompt.net/guides/install-magento-2-debian10-ubuntu8/<p>This guide will walk you through taking an brand new server to having a working Magento instance in 10 minutes or less. This guide follows all the recommended guidelines suggested by the Magento developers.</p>
<p>Prerequisites:</p>
<ol>
<li>An Ubuntu 18.04 LTS or Debian Buster server with at least 1GB of RAM for an archive based install or 2GB for the composer install.</li>
<li>Basic knowledge of using the Linux command line.</li>
<li>The hostname of your store must resolve (point) to the IP address of your server before you start this guide if you want to install an SSL certificate.</li>
<li>An account with Magento. Login or sign up <a href="https://account.magento.com">here</a>.</li>
</ol>
<p>You will need to get your access keys from your Magento Marketplace account by going to <strong>My Profile -> Access Keys</strong> and making a note of them.</p>English Grammar and Style Checking in Gedit
https://bash-prompt.net/guides/grammar_checking_gedit/
Mon, 28 Oct 2019 00:00:00 +0000https://bash-prompt.net/guides/grammar_checking_gedit/<p>I love gedit as a MarkDown editor. It’s simple, clean, fast and easy to configure. It does <em>almost</em> everything I need from a simple editor. The only feature that I miss is a grammar checker and style checker. So I got one working in gedit.</p>
<p>I got grammar checking working in gedit by combining two tools:</p>
<ol>
<li><a href="https://wiki.gnome.org/Apps/Gedit/Plugins/ExternalTools">gedit External Tools Plugin</a></li>
<li><a href="https://github.com/btford/write-good">write-good</a></li>
</ol>
<p>The external tools plugin allows gedit to execute external commands which can manipulate or process the current document. write-good is a command-line tool that will evaluate English text that is passed to it and highlight grammar errors and dubious style choices such as passive voice.</p>Using Telnet To Debug Web Servers
https://bash-prompt.net/guides/telnet-http/
Mon, 21 Jan 2019 00:00:00 +0000https://bash-prompt.net/guides/telnet-http/<h3 id="troubleshooting-web-servers">Troubleshooting web servers</h3>
<p>When a webserver is setup and configured, especially when it will be serving several sites from the same IP being able to craft exact HTTP(S) requests is important to troubleshoot and ensure everything is working as you want it to.</p>
<p>If you notice in the Samba example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>telnet samba.example.com <span style="color:#ae81ff">445</span>
</span></span><span style="display:flex;"><span>Trying 172.31.25.31...
</span></span><span style="display:flex;"><span>Connected to samba.example.com.
</span></span><span style="display:flex;"><span>Escape character is <span style="color:#e6db74">'^]'</span>.
</span></span></code></pre></div><p>The connection pauses and this is where commands can be issued to the server you have connected to. In the case of a web server we can issue HTTP requests as they are in plain text.</p>Fun With Units
https://bash-prompt.net/guides/units/
Mon, 13 Aug 2018 00:00:00 +0000https://bash-prompt.net/guides/units/<p>Converting between units is a task that comes up occasionally and can get tricky especially if you want to script the conversions.</p>
<p>Enter the command line tool; units.</p>
<p>This fantastic little tool allows the conversion between any compatible units with ease. It can be used either interactively (which is how we will use it here) or it will accept standard input.</p>
<p>Once you have installed it simply run it without nay options to open the interactive shell:</p>How To Kill A Process That Won't Respond To ctrl-C
https://bash-prompt.net/guides/kill-process/
Tue, 12 Jun 2018 00:00:00 +0000https://bash-prompt.net/guides/kill-process/<p>Sometimes, particularly when writing a bash scripts or one liners, a process is attached to the terminal and cannot be stopped with the usual ctrl-c or ctrl-q.</p>
<p>There are two ways to kill this process. The first is to open another terminal and find the PID of the process with <code>ps</code> or <code>top</code> and then issue the <code>kill</code> command:</p>
<pre tabindex="0"><code>kill 7653
</code></pre><p>However, this involves opening an additional terminal, logging in etc.</p>Using Your Android Phone For Voice Dictation On Linux
https://bash-prompt.net/guides/android-dictation/
Fri, 20 Apr 2018 00:00:00 +0000https://bash-prompt.net/guides/android-dictation/<p>Voice recognition and automatic dictation have always been a difficult (and expensive) task on most operating system including Linux.</p>
<p>However, recently some very large companies (Google, Apple, Amazon) have seen the value of being able to communicate vocally with their devices. In order to make this successful they have had to make their voice recognition fast, accurate and built into their devices and offered for free.</p>
<p>We can take advantage of their hard work and R&D dollars to get excellent dictation on the Linux desktop by using <a href="https://community.kde.org/KDEConnect">KDEConnect</a>. Despite being a KDE application is can be easily installed and used on Gnome as well. Nick Congleton has written a guide to installing KDEConnect on Gnome <a href="https://www.maketecheasier.com/integrate-kde-connect-with-gnome-shell/">here</a>.</p>How To Quickly Evaluate A Computer For Potential Crypto-Mining
https://bash-prompt.net/guides/miner-calc/
Mon, 26 Mar 2018 00:00:00 +0000https://bash-prompt.net/guides/miner-calc/<p>I’ve been reading about cryptojacking (abusing someone’s browser to mine crypto-coins) and crypto-mining in general and wondered if is possible to make money mining cryptocurrencies on some of the hardware that I have access to.</p>
<p>The machines that I used for these tests are:</p>
<ol>
<li>My laptop - ASUS ROG GL551JW:</li>
</ol>
<ul>
<li>Intel i7 8 Core @2.60GHz</li>
<li>NVIDIA Corporation GM107M</li>
<li>~120 Watts peak draw</li>
</ul>
<ol start="2">
<li>A bottom tier generic VM with a single VCPU (Xeon)</li>
</ol>
<ul>
<li>$10 USD per month</li>
</ul>
<ol start="3">
<li>An AWS <a href="https://aws.amazon.com/ec2/instance-types/p2/">p2.xlarge</a>:</li>
</ol>
<ul>
<li>4 x VCPU (Xeon)</li>
<li>1 NVIDIA K80 GPU</li>
<li>$0.29 per hour (spot instance pricing)</li>
</ul>
<p>Next, I needed to find out how good they are at mining cryptocurrency and work out if they are able to make a profit i.e. generate more cryptocurrency than either the electricity consumption in the case of my laptop or the monthly rental in the case of the cloud machines needs.</p>Specialised Verses General Tools
https://bash-prompt.net/guides/specialized_v_general/
Tue, 20 Mar 2018 00:00:00 +0000https://bash-prompt.net/guides/specialized_v_general/<h2 id="or-how-i-learned-to-stop-worrying-and-love-top">Or How I Learned To Stop Worrying And Love <code>top</code></h2>
<p>First of all, if you’re running Linux on your laptop and a media server in your house or you’re the admin of a small number of servers that you have complete control over then this article is not aimed at you. You can configure your systems however you want. I won’t judge.</p>
<p>This article is aimed at admins that work in larger organizations where there exists a heterogeneous Linux environment i.e. servers, VM’s, containers, networking gear etc, that are running different distros at different versions with different policies. The normal way that things happen in a Linux based organization. This article is aimed at admins starting out in there.</p>How To Debug Your WebServer From The Command Line
https://bash-prompt.net/guides/http-headers/
Fri, 09 Mar 2018 00:00:00 +0000https://bash-prompt.net/guides/http-headers/<p>When installing a configuring and modifying a website it is frequently necessary to make changes to the way that the webserver is serving the site e.g. enabling <code>mod_deflate</code> or enabling HTTP2. However, these changes can be somewhat difficult to verify by viewing the site in a browser.</p>
<p>There are lots of websites that will do the checking for you such as <a href="https://www.giftofspeed.com/gzip-test/">GiftOfSpeed.com</a> which will check if GZIP is enabled. However, this being Linux, if you’re on the command line and you have a problem, it’s an almost given certainty that some clever person met the same problem before you and there’s a tool that will do the job.</p>Making Use Of The search Option In resolv.conf
https://bash-prompt.net/guides/resolv-conf/
Thu, 08 Feb 2018 00:00:00 +0000https://bash-prompt.net/guides/resolv-conf/<p>The <code>/etc/resolv.conf</code> file configures how the Linux system resolves hostnames. It contains the resolvers that the system will query in order to convert hostnames to IP addresses and vice versa.</p>
<p>In addition to listing resolving servers the <code>resolv.conf</code> file can also take the <code>search</code> option that will save you a great deal of typing in the right situation.</p>
<p>The <code>search</code> option takes a list of space-separated hostnames. Here is an example of the search option being used for two domain names:</p>Using od To See How Text Is Formatted
https://bash-prompt.net/guides/od/
Wed, 07 Feb 2018 00:00:00 +0000https://bash-prompt.net/guides/od/<p>A large part of using a shell is manipulating text strings using tools such as <code>grep</code>, <code>sed</code> and <code>cut</code>. Systems Administrators often have to take a file as input with an unknown format and extract only the text strings they need.</p>
<p>This is usually fairly simple - until it’s not. The situation is complicated because shells will interpret certain characters in strings and display something other than the literal characters. The two most common are <code>\n</code> for a new line (think a carriage return) and <code>\t</code> for a tabbed space.</p>Reading And Searching Compressed Files
https://bash-prompt.net/guides/read-write-gzip/
Fri, 12 Jan 2018 00:00:00 +0000https://bash-prompt.net/guides/read-write-gzip/<p><a href="http://www.gzip.org/">gzip</a> and <a href="http://www.bzip.org/">bzip2</a> are the most common compression utilities used on Linux and are used pretty much anywhere compression is required. This is especially true of log files because the <a href="https://github.com/logrotate/logrotate">logrotate</a> utility is usually configured by default to run when a server such as Apache2 is installed. <code>logrotate</code> periodically takes the current working log file, gives it a version number and compresses it leaving a new, empty log file for the application to write to.</p>Why You Should Still Love Telnet
https://bash-prompt.net/guides/telnet/
Sun, 31 Dec 2017 00:00:00 +0000https://bash-prompt.net/guides/telnet/<p>Telnet, the protocol and the command line tool, were how system administrators used to log into remote servers. However, due to the fact that there is no encryption all communication, including passwords, are sent in plaintext meant that Telnet was abandoned in favour of SSH almost as soon as SSH was created.</p>
<p>For the purposes of logging into a remote server, you should never, and probably have never considered it. This does not mean that the <code>telnet</code> command is not a very useful tool when used for debugging remote connection problems.</p>How To Use Your Entire CPU In Bash With Parallel
https://bash-prompt.net/guides/parallell-bash/
Tue, 19 Dec 2017 00:00:00 +0000https://bash-prompt.net/guides/parallell-bash/<p>When a bash command is run it usually gets run in a single thread. This means that it will all the processing work will get executed on a single CPU. As CPU’s have scaled out and increased their core count this means that only a small fraction of the available CPU resources will get used to work on your process.</p>
<p>These unused CPU resources can make a big difference when the work we are trying to get done is bound by the speed that the CPU can crunch the data. This typically happens during media conversion e.g. picture and video, and data compression.</p>How To Tell If Your Linux Server Has Been Compromised
https://bash-prompt.net/guides/server-hacked/
Tue, 28 Nov 2017 00:00:00 +0000https://bash-prompt.net/guides/server-hacked/<p>A server being compromised or hacked for the purpose of this guide is an unauthorized person or bot logging into the server in order to use it for their own, usually negative ends.</p>
<p>Disclaimer:
If your server has been compromised by a state organization like the NSA or a serious criminal group then you will not notice any problems and the following techniques will not register their presence.</p>
<p>However, the majority of compromised servers are carried out by bots i.e. automated attack programs, in-experienced attackers e.g. “script kiddies”, or dumb criminals.</p>Protecting Your Website From Application Layer DOS Attacks With mod_evasive
https://bash-prompt.net/guides/mod_proxy/
Mon, 27 Nov 2017 00:00:00 +0000https://bash-prompt.net/guides/mod_proxy/<p>There exist many ways of maliciously taking a website offline. The more complicated methods involve technical knowledge of databases and programming. A far simpler method is known as a “Denial Of Service”, or “DOS” attack. This attack derives its name from its goal which is to deny your regular clients or site visitors normal website service.</p>
<p>There are, generally speaking, two forms of DOS attack;</p>
<ol>
<li>Layer 3,4 or Network-Layer attacks.</li>
<li>Layer 7 or Application-Layer attacks.</li>
</ol>
<p>The first type of DOS attack, network-layer, is when a huge quantity of junk traffic is directed at the web server. When the quantity of junk traffic exceeds the capacity of the network infrastructure the website is taken offline.</p>The Pinky Finger Habits Of Experienced Sysadmins
https://bash-prompt.net/guides/habits-sysadmin/
Fri, 03 Nov 2017 00:00:00 +0000https://bash-prompt.net/guides/habits-sysadmin/<p>Over my career as a Systems Administrator, I have acquired some productive habits when I’m working on the command line that I have picked up from sysadmins more experienced than myself.</p>
<p>The two here both involve using your pinky fingers as they are the <code>[ENTER]</code> and <code>[TAB]</code> keys.</p>
<h2 id="hit-the-enter-key-between-every-command">Hit the enter key between every command</h2>
<p>This habit is very simple, just hit the <code>[ENTER]</code> key a few times between entering every command. Rather than explain why take a look at the following two terminal sessions of the same commands being entered along with their output:</p>The Simplest Way To Move Files To And From Your Phone
https://bash-prompt.net/guides/simple-file-transfer/
Fri, 27 Oct 2017 00:00:00 +0000https://bash-prompt.net/guides/simple-file-transfer/<p>Sometimes the simplest seeming jobs end up being more annoying than they should be. Moving a file from your computer to your phone and vice-versa should be a fairly simple task. However, it’s usually a mess of deciding to email it to yourself, put it into Google docs or Dropbox or hunting around for that USB cable (and appropriate adaptors).</p>
<p>The following method solves this problem but at the expense of being <strong>ABSOLUTELY INSECURE</strong>. It uses no encryption and no passwords. Your data is un-encrypted in transit and at rest. If you’re thinking of transferring anything secret then either don’t do it like this or encrypt it before you transfer it. However, the number of times I need to move a picture or PDF far outnumbers the number of times I want to move super-secret personal information.</p>How To Use Apache2 for SSL Termination With Varnish
https://bash-prompt.net/guides/apache-varnish/
Mon, 16 Oct 2017 00:00:00 +0000https://bash-prompt.net/guides/apache-varnish/<p>These days it is becoming mandatory to serve websites only via HTTPS. This is great for security but makes deploying a <a href="https://varnish-cache.org/">Varnsh</a> caching server more difficult.</p>
<p>This is because, Varnish does not, and has <a href="https://varnish-cache.org/docs/trunk/phk/ssl_again.html">no plans</a> to, support HTTPS. As a result, Varnish cannot simply be configured to listen on the external IP on port 443 for incoming HTTPS connections as it does for HTTP connections.</p>
<p>An intermediary program is therefore required to accept the HTTPS connections, decrypt them, and then hand them off as HTTP requests to Varnish and then re-encrypt them on the way out. This program is called an SSL terminator.</p>Three Alternatives for Enabling Two Factor Authentication For SSH On Ubuntu 16.04 And Debian Jessie
https://bash-prompt.net/guides/ssh-2fa/
Mon, 02 Oct 2017 00:00:00 +0000https://bash-prompt.net/guides/ssh-2fa/<p>Security is now more important than ever and securing your SSH server is one of the most important things that you can do as a systems administrator. Traditionally this has meant disabling password authentication and instead using SSH keys. Whilst this is absolutely the first thing you should do that doesn’t mean that SSH can’t be made even more secure.</p>
<p>Two-factor authentication simply means that two means of identification are required to log in. These could be a password and an SSH key, or a key and a 3rd party service like Google. It means that the compromise of a single authentication method does not compromise the server.</p>Secure Your Phone With OpenVPN On Ubuntu 18.04 In 10 Minutes
https://bash-prompt.net/guides/android-openvpn/
Sat, 30 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/android-openvpn/<p><a href="https://openvpn.net/">OpenVPN</a> is an open source secure tunnel application. It creates an encrypted tunnel between a client and a server. Any data passing through the tunnel is immune from being read by anyone that is able to intercept the data. In this case, the client will be your Android phone and the server will be a server that you own running OpenVPN. It is better to host your own VPN as a commercial services <a href="https://arstechnica.com/information-technology/2017/01/majority-of-android-vpns-cant-be-trusted-to-make-users-more-secure/">cannot always be trusted</a>.</p>Adding Google Analytics and AdSense to a Hugo website
https://bash-prompt.net/guides/custom-html-jugo/
Fri, 29 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/custom-html-jugo/<p>Hugo is a great static website generator, I use it for this blog and am absolutely loving it! However, the first issue that I came across was that the theme that I’m using <a href="https://github.com/calintat/minimal">Minimal</a> does not come with any configuration options for using Google Analytics or including Google AdSense ads. I also wanted to include some custom headers such as a favicon and some description lines.</p>
<p>It took a little reading and tinkering to get this working so I thought I would document how I got this working and hopefully save someone else some time.</p>Extracting Information From Logs - Part 1
https://bash-prompt.net/guides/using-logs-1/
Thu, 28 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/using-logs-1/<h2 id="introduction">Introduction</h2>
<p>System administrators are expected to solve many different problems and answer diverse questions throughout their working day. A common request is to answer “How many times did X do Y”. This information is typically not stored directly, and there are no counters or pretty statistics pages for most Linux server applications. However, there are log files. Every time a web page is requested, an email sent or a login made, the event is recorded in a log file. An essential skill for any system administrator is to be to able parse through log files and extract useful information.</p>Extracting Information From Logs - Part 2
https://bash-prompt.net/guides/using-logs-2/
Thu, 28 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/using-logs-2/<p>In <a href="https://bash-prompt.net/guides/using-logs-1/">Part 1</a> of this series, we extracted the IP addresses of machines making unauthorized SSH connections from a <code>/var/log/secure</code> file. The result of that exercise was a file containing a list of IP addresses with each IP representing a failed login attempt. If you don’t want to generate that list you can down load it <a href="https://bash-prompt.net/Data/IPs.txt">here</a>.</p>
<h2 id="the-problem">The problem</h2>
<p>The scenario that we will work on in these guides is a common question faced by system administrators. We will imagine that we have been asked to find out what countries unauthorized SSH login attempts are coming from and rank them according to the frequency of their attacks.</p>Extracting Information From Logs - Part 3
https://bash-prompt.net/guides/using-logs-3/
Thu, 28 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/using-logs-3/<h2 id="introduction">Introduction</h2>
<p>In <a href="https://bash-prompt.net/guides/using-logs-1/">Part 1</a> and <a href="https://bash-prompt.net/guides/using-logs-2/">Part 2</a> of this series, we extracted the IP addresses that made unauthorized SSH login attempts and then sorted and ranked them. Now that we have a ranked list of IP’s we need to find out which countries these IP addresses originated from. The ranked list IP’s that we will use in this section can be downloaded from <a href="https://bash-prompt.net/Data/sorted-IPs.txt">here</a>.</p>
<h2 id="the-problem">The problem</h2>
<p>The scenario that we will work on in these guides is a common question faced by system administrators. We will imagine that we have been asked to find out what countries unauthorized SSH login attempts are coming from and rank them according to the frequency of their attacks.</p>How To Install Magento 2 on CentOS 7 In 10 Minutes
https://bash-prompt.net/guides/install-magento-centos/
Tue, 26 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/install-magento-centos/<p>This guide is now outdated. If you are looking for an up-to-date version for CentOS 8 please take a look at:</p>
<p><a href="https://bash-prompt.net/guides/magento-centos-8-10m/">https://bash-prompt.net/guides/magento-centos-8-10m/</a></p>
<p>The Magento developers provide documentation covering installing Magento, however, they have created too much documentation. They list many options at each step which are spread across many pages of dense information. I have gone through this information and extracted a simple walk through that will get you from a fresh CentOS 7 server to a working Magento installation in under 10 minutes.</p>Simulate System Loads
https://bash-prompt.net/guides/create-system-load/
Sun, 24 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/create-system-load/<p>Sysadmins often need to discover how the performance of an application is affected when the system is under certain types of load. This means that an artificial load must be re-created. It is, of course, possible to install dedicated tools to do this but this option isn’t always desirable or possible.</p>
<p>Every Linux distribution comes with all the tools needed to create load. They are not as configurable as dedicated tools but they will always be present and you already know how to use them.</p>Speed Up Magento2 With Varnish
https://bash-prompt.net/guides/magento-varnsh/
Sun, 24 Sep 2017 00:00:00 +0000https://bash-prompt.net/guides/magento-varnsh/<p>Varnish is a reverse proxy that speeds up web sites by running in front of the web server and serving static websites assets such as images from RAM. Requests for new or dynamic assets such as PHP file are passed on to the web server. Varnish is extremely fast at serving static assets, much faster than a regular web server. The increase in speed is especially noticeable for websites like Magento stores that have a large number of images in each page. This makes a magento store an excellent candidate for running behind a Varnish server.</p>