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 pwgen , but sometimes that is not available on the system you are working on. 
 When pwgen isn’t available, you can sanitize the output of /dev/urandom so that you only get text and numbers. The following command will output a…
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. 
 I’ve used lots of methods to create temporary directories and files that I end up recreating every time. 
 That is, until I found mktemp . 
 How To Use mktemp 
 By…
I recently upgraded a server to Debian Trixy, and I noticed some new lines in /var/log/auth.log : 
 2025-11-30T00:17:48.220870+00:00 WEB sshd [ 55238 ] : srclimit_penalise: ipv4: new 1.2.3.4/32 active penalty of 1s seconds for penalty: connections without attempting authentication
 After a little searching, I found that the new version of the SSH server included with Trixy had a new…
I recently looked at generating spoken audio from text using here . I have found another way to do this, but locally, instead of sending all the data to Google. 
 The tool that I used is called piper1-gpl . 
 Install Piper 
 Use the Python package manager pip to get it installed: 
 pip install piper-tts
 You may need to use your distro’s package manager to get pip…
WireGuard is an excellent replacement for OpenVPN. If you haven’t already started using it, check out my quick start guide . 
 A small annoyance I’ve had with WireGuard is that when I want to see who is connected, their data transfer, etc., the wg output only identifies them by their public key. E.g.: 
 sudo wg

peer: sX4eqmye8hqC2eu+9zJuS6Nh56UdV/foyNd5hK+gwjQ=
…
Edit I have found a new way to do this locally that gives excellent results. You can read the guide here /Edit 
 I’ve been practicing my Spanish recently, and I wanted a tool to output spoken Spanish from a text file as I read along. 
 I tried a few tools like espeak-NG , pyttsx3 and
 Festival but the results were a little robotic. 
 The tool that produced the best results…
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. 
 cURL allows access to an IP address of a server and supply a hostname, bash-prompt.net . 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. 
 The cURL…
We typically use the whois command to get information about domain names. whois can also get the organization information about the company that an IP address is registered to. 
 Every IP address is registered to an organization by an IP authority. You can find the list authorities here . When an organization requests and is allocated an IP address, typically in a block, they must supply…
Sometimes the output of commands or the information in log files is not formatted very well which makes it difficult to understand. 
 For example, here are the top ten lines of a CPU benchmark log file: 
 $ 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…
dd 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 dd over something viable, destroying it. 
 There are…
Here is the list of all the Bash debugging posts: 
 
 Verbose Output 
 Using exit command 
 Using echo command 
 Using ShellCheck 
 Jummping Forward 
 
 The exit command will allow you to halt a script without executing everything after the exit command. 
 If you want to do the opposite and skip some of the script there is no builtin command to do this. This is…
Here is the list of all the Bash debugging posts: 
 
 Verbose Output 
 Using exit command 
 Using echo command 
 Using ShellCheck 
 Jummping Forward 
 
 This debugging tool is useful in your Bash scripts and also in any Bash one-liners that you write. 
 The echo tool will print any input you give it. Most importantly, it will not execute any commands that are…
Here is the list of all the Bash debugging posts: 
 
 Verbose Output 
 Using exit command 
 Using echo command 
 Using ShellCheck 
 Jummping Forward 
 
 This one is pretty simple. Either install ShellCheck with your package manager or use the website tool to check your scripts. 
 It will check for any buggy code and also offer syntax advice like quoting…
Here is the list of all the Bash debugging posts: 
 
 Verbose Output 
 Using exit command 
 Using echo command 
 Using ShellCheck 
 Jummping Forward 
 
 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. 
 Bash comes with a couple of…
Here is the list of all the Bash debugging posts: 
 
 Verbose Output 
 Using exit command 
 Using echo command 
 Using ShellCheck 
 Jummping Forward 
 
 The exit command in a Bash scrip will immediatly cause the scrip to stop as soon it is exit is executed. 
 This is very useful in two ways: 
 
 This can be used to stop the scrip immediatly after your…
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. 
 On modern multi-core systems, this is wasting a lot of CPU resources and time. 
 xargs is a complex tool that comes with the ability to run processes in parallel. 
 The general…
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 Opus 
 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 
 I downloaded Don Quixote…
Sometimes you need to check if a port is open and available e.g. not firewalled, from your current location. 
 The following netcat command will instantly tell you if you a port is open and you can connect to it on a remove server: 
 netcat -w1 -z -v <HOST> <PORT>
 E.g.: 
 netcat -w1 -z -v bash-prompt.net 443
 If the port is open you’ll get the following response: 
 $…
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. 
 This one will take something you’re interested in, say IPs from a log file, and print them in a sorted list. 
 For example, say I wanted to see the bots trying to access SSH. The /var/log/auth.log (Debian) prints lines like the…
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. 
 The cURL command line tool provides excellent options to print out exactly what it’s doing when it requests an object from a remote server. 
 Simply use the following options when using cURL to print the complete interaction between…
I like to run my sites without a www. You’re looking at this site like that e.g. http://bash-prompt.net . 
 Some traffic always arrives at http://www.bash-prompt.net which sometimes breaks things, especially with dynamic sites. 
 This problem can be solved using the Apache module mod_rewrite . But I’ve had problems with that and it’s an overcomplicated way to do things.…
I like to run my sites without a www. You’re looking at this site like that i.e. https://bash-prompt.net . 
 Some traffic always arrives at https://www.bash-prompt.net which sometimes breaks things, especially with dynamic sites. 
 This problem can be solved using the Apache module mod_rewrite . But I’ve had problems with that and it’s an overcomplicated way to do things.…
OpenSSL 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. 
 You might be interested in seeing how you can benchmark how fast your server can serve HTTPS requests as a part of tuning it. 
 the openssl command comes with this ability built in. 
 The following command will prompt…
DNS caching is a good thing. When your local resolver, in this case, systemd-resolved , 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. 
 However, this can become a problem if you’re changing DNS…
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 stdout (standard output) or an error message on stderr (standard error). 
 The usual way to do this is with the classic: 
 $ <COMMAND> 2>&1 >/dev/null
 This redirects stderr into stdout and then sends stdout to…
Entering a password incorrectly too many times happens to all of us. It could be entering the desktop or running a sudo command from the command line as a user. After 3 failed attempts sudo will lock that user account from logging in for a period. 
 Here’s how to reset sudo so they can log in again immediately. Here is me deliberately entering an incorrect password three times for user :
Introduction 
 WireGuard is a modern V irtual P rivate N 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 OpenVPN which is, when compared to WireGuard, much harder to set up and configure. 
 In this guide, I will walk you through installing…
Over on my personal website https://elliotcooper.com I encountered a problem when I created a redirect from https://www.elliotcooper.com to https://elliotcooper.com . The web server, in this case, Apache2, first negotiates the HTTPS connection before doing the redirect. 
 This was a problem because the Let’s Encrypt certificate I generated was only valid for the Common Name (CN)…
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. 
 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. 
 All you need to do is to hit: 
 CTRL+x CTRL+e
 while your working on your…
Quickly discovering the speed between two Linux servers can often be a chore of copying large files around. 
 There is a better way with iperf . 
 iperf can be used to quickly setup a server and client process on two Linux servers and report the max network throughput between them. 
 Server 
 Run the following command on the server machine: 
 iperf -s -i 10
 
 -s -…
A common job for a system administrator is to troubleshoot a Linux server to find out why it’s running slowly. 
 The following command will give you a great overview and should only take less than a minute to review. 
 uptime 
 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…
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. 
 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. 
 The following command will very quickly spider a website and…
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. 
 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. 
 The following command will very quickly spider a website and…
Not too many people know that Apache2 provides a simple caching module mod_cache . 
 It’s super simple to enable for a static site like this one and gave me a %65 performance increase! 
 Here’s how. 
 Enable the Apache2 mods 
 First, enable the two cache mods that are installed along with Apache2: 
 a2enmod cache
a2enmod cache_disk
systemctl reboot
…
mdadm is the tried and trusted software RAID tool for Linux. You might think that getting some practice with mdadm is difficult because you need several storage devices. 
 That’s not true as you can simple create some virtual devices to practice on. 
 Here’s how. 
 Create the virtual block devices 
 Use dd to create three 32MB files: 
 dd if=/dev/zero of=disk1 bs=1M…
SSH keys are the best way of logging into Linux servers. But traditional keys have their limitations. 
 They never expire 
 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. 
 You even can issue new…
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. 
 That’s a pain that interrupts your workflow. 
 Instead, use this simple command to create a popup notification on your desktop that will let you know the process has finished. 
 First, install…
Some Bash tools are so good that then end up being the goto tool for a particular application year after year. 
 IPTraf now IPTraf-ng , 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. 
 Just fire it up with iptraf-ng to get started. This will bring you to a choice menu: 
 
 IP traffic monitor 
…
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. 
 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.…
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. 
 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. 
 The example script, print-string.sh , does nothing else…
We all write Bash scripts. They are convenient, fast and powerful . But how to make them safer? 
 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. 
 These options are configured with the set option that you can read all…
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. 
 A couple of easy wins here are to replace the traditional interpreter line and drop echo commands. 
 Script Interpreter 
 The traditional interpreter line at the…
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! 
 It turns out that a couple of changes to your dnf.conf file will get you back into the 21st century. 
 Just edit your dnf.conf file: 
 nano /etc/dnf/dnf.conf
 And make sure you…
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 wget tool. 
 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…
The GNU nano is a superb Linux text editor. And you absolutely should use it. It’s not a fully-featured IDE nor does it claim to be. 
 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. 
 I use nano for all my processional Linux administration and content…
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 https://serverfault.com they often don’t explain all the options they use. 
 You could use the man page to check them all but nobody’s got time for that. 
 In stead use https://explainshell.com . Just dump the command along…
We all use find to locate stuff on the command line. The -exec option allows us to execute a command on the located objects without having to pipe the output anywhere. 
 This is convenient but slow. 
 Find executes the command for every matched file. For example, the following command runs ls -la individually for every file in the /home/user/Documents/ directory: 
 find…
Sometimes you need to determine how many CPU cores a system has. This might be when you’re running make to use some or all of your CPU cores or some compression tools that take a CPU cores argument. 
 If you’re not trying to find this number in a script you can grep the contents of /proc/cpuinfo : 
 cat /proc/cpuinfo | grep processor
processor : 0
processor :…
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. 
 I used to think that the only fix was to close the terminal window and SSH in again. 
 This isn’t the only option as SSH comes with some escape sequences.…
Everyone knows how to generate a new SSH key: 
 ssh-keygen -t ed25519
 (you really should be using ed25519 if your environment supports it). 
 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. 
 That option is the -a <NUMBER> option. This option…