This final chapter is a bit of a mixed bag. We cover a range of topics, from virtual machines to security to new ways to use Linux. What the topics in this chapter have in common is that most of them are relevant for you only if you have a specific use case in mind, or if you require them in a professional setup.
We start off the chapter with how processes on a single machine can communicate and share data. There is a wealth of interprocess communication (IPC) mechanisms available, and here we focus on well-established and -used features: signals, named pipes, and Unix domain sockets.
Then, we look at virtual machines (VMs). In contrast to the containers we discussed in “Containers” (which are good for application-level dependency management), VMs provide strong isolation for your workloads. You come across VMs most often in the context of the public cloud and in the general case in data centers. Having said that, using VMs locally can also be useful, such as for testing or to simulate distributed systems.
The next section in this chapter focuses on modern Linux distributions, which are usually container-centric and assume immutability. You’ll often find said distros in the context of distributed systems such as Kubernetes.
We then move on to selected security topics, covering Kerberos, a widely used authentication suite, and pluggable authentication modules (PAM), an extension mechanism Linux provides for authentication.
In the last part of this chapter, we review Linux solutions and use cases that, at the time of writing, are not yet mainstream. But they could be relevant to you and are worth exploring.
Interprocess Communication
In Linux there is a long list of interprocess communication (IPC) options available, ranging from pipes to sockets to shared memory. IPC enables processes to communicate, synchronize activities, and share data. For example, the Docker daemon uses configurable sockets to manage containers. In this section, we review some popular IPC options and their use cases.
Signals
Signals were originally developed as a way for the kernel to notify user space processes about a certain event. Think of signals as an asynchronous notification sent to a process. There are many signals available (use the man 7 signal command to learn more), and most of them come with a default action, such as stop or terminate the process.
With most signals, you define a custom handler, rather than letting Linux carry on with the default action. This is useful when you want to, for example, do some clean-up work or simply ignore certain signals. Table 9-1 shows the most common signals that you should be familiar with.
Table 9-1. Common signals
| Signal | Meaning | Default action | Handle option | Key combination |
| --- | --- | --- | --- | --- |
| SIGHUP | Tell a daemon process to reread its config file | Terminate process | nohup or custom handler | N/A |
| SIGINT | User interruption from keyboard | Terminate process | Custom handler | Ctrl+C |
| SIGQUIT | User quit from keyboard | core dump and terminate process | Custom handler | Ctrl+\ |
| SIGKILL | Kill signal | Terminate process | Cannot be handled | N/A |
| SIGSTOP | Stop process | Stop process | Cannot be handled | N/A |
| SIGTSTP | User caused stop from keyboard | Stop process | Custom handler | Ctrl+Z |
| SIGTERM | Graceful termination | Terminate process | Custom handler | N/A |
There are also signals that don’t have defined meanings ( SIGUSR1 and SIGUSR2 ) that processes can use to communicate with each other, sending asynchronous notification, if both parties agree on the semantics of the signal.
One typical way to send a signal to a process is the somewhat strangely named kill command (due to its default behavior to cause processes to terminate):
$ while true ; do sleep 1 ; done &
[1] 17030
$ ps
PID TTY TIME CMD
16939 pts/2 00:00:00 bash
17030 pts/2 00:00:00 bash
17041 pts/2 00:00:00 sleep
17045 pts/2 00:00:00 ps
$ kill 17030
[1]+ Terminated while true; do
sleep 1;
done
We set up a very simple program here that simply sleeps. With & , we put it into the background.
The shell job control confirms that our program runs as a job with ID 1 in the background and reports its PID ( 17030 ).
Using ps , we check if the program is still running.
Here is our program (compare PID).
By default, kill sends the SIGTERM to the process, and the default action is to terminate the process gracefully. We provide kill with the PID of our process ( 17030 ), and since we didn’t register a custom handler, it is terminated.
Now we’ll look at how to handle a signal with trap . This allows us to define a custom handler in a shell environment (command line or script):
$ trap "echo kthxbye" SIGINT ; while true ; do sleep 1 ; done
^Ckthxbye
With trap "echo kthxbye" SIGINT , we register a handler, telling Linux that when the user presses Ctrl+C (causing a SIGINT signal to be sent to our process), Linux should execute echo kthxbye before the default action (terminate).
We see the user interruption ( ^C is the same as Ctrl+C) and then our custom handler getting executed, printing kthxbye , as expected.
Signals are a simple yet powerful IPC mechanism, and now you know the basics of how to send and handle signals in Linux. Next up, we discuss two more elaborate and powerful IPC mechanisms—named pipes and UNIX domain sockets.
Named Pipes
In “Streams” , we talked about pipes ( | ) that you can use to pass data from one process to another by connecting the stdout of one process with stdin of another process. We call these pipes unnamed . Taking this idea a step further, named pipes are pipes to which you can assign custom names.
Just like unnamed pipes, named pipes work with normal file I/O ( open , write , etc.) and provide first in, first out (FIFO) delivery. Unlike unnamed pipes, the lifetime of a named pipe is not limited to the processes it’s used with. Technically, named pipes are a wrapper around pipes, using the pipefs pseudo filesystem (see “Pseudo Filesystems” ).
Let’s see a named pipe in action to better appreciate what you can do with them. We create a named pipe called examplepipe in the following, along with one publisher and one consumer process:
$ mkfifo examplepipe
$ ls -l examplepipe
prw-rw-r-- 1 mh9 mh9 0 Oct 2 14:04 examplepipe
$ while true ; do echo "x" > examplepipe ; sleep 5 ; done &
[1] 19628
$ while true ; do cat < examplepipe ; sleep 5 ; done &
[2] 19636
x
x
...
We create a named pipe called examplepipe .
Looking at the pipe with ls reveals its type: the first letter is a p , indicating it’s a named pipe we’re looking at.
Using a loop, we publish the character x into our pipe. Note that unless some other process reads from examplepipe , the pipe is blocked. No further writing into it is possible.
We launch a second process that reads from the pipe in a loop.
As a result of our setup we see x appearing on the terminal, roughly every five seconds. In other words, it appears every time the process with PID 19636 is able to read from the named pipe with cat .
Named pipes are easy to use. Thanks to their design, they look and feel like normal files. But they’re also limited, since they support only one direction and one consumer. The next IPC mechanism we look at addresses these limitations.
UNIX Domain Sockets
We’ve already talked about sockets in the context of networking. There are also other kinds of sockets that work exclusively in the context of a single machine, and one such kind is called UNIX domain sockets : these are bidirectional, multiway communication endpoints. This means you can have multiple consumers.
Domain sockets come in three flavors : stream-oriented ( SOCK_STREAM ), datagram-oriented ( SOCK_DGRAM ), and sequenced-packet ( SOCK_SEQPACKET ). The addressing works based on filesystem pathnames. Rather than having IP addresses and ports, a simple file path is sufficient.
Usually, you would be using domain sockets programmatically . However, you might find yourself in a situation where you need to troubleshoot a system and want to use, for example, the socat tool from the command line to interact manually with a socket.
Virtual Machines
This section is about an established technique that allows us to emulate multiple VMs using a physical machine such as your laptop or a server in a data center. This yields a more flexible and powerful way to run different workloads, potentially from different tenants in a strongly isolated manner. We focus on hardware-assisted virtualization for x86 architectures.
In Figure 9-1 , you see the virtualization architecture on a conceptual level, comprising the following (starting from the bottom):
The CPU
Must support hardware virtualization.
The kernel-based virtual machine
Found in the Linux kernel; discussed in “Kernel-Based Virtual Machine” .
Components in the user space
Components in the user space include the following:
A Virtual Machine Monitor (VMM)
Manages VMs and emulates virtual devices, such as QEMU and Firecracker (see “Firecracker” ). There is also libvirt , a library that exposes a generic API aiming to standardize VMM, which you can use programmatically (not explicitly shown in the figure; consider it part of the VMM block).
The guest kernel
Typically also a Linux kernel but could also be Windows.
The guest processes
Running on the guest kernel.
Figure 9-1. Virtualization architecture
The processes that run natively on the host kernel (in Figure 9-1 , process 1 and process 2) are isolated from the guest processes. This means that in general the physical CPU and memory of the host are not affected by guest activities. For example, if there’s an attack going on in the VM, the host kernel and processes are unaffected (as long as the VM is not given special access to the host system). Note that there may be exceptions to this in practice, such as rowhammer or Meltdown and Spectre .
Kernel-Based Virtual Machine
The Kernel-based Virtual Machine (KVM) is a Linux-native virtualization solution for x86 hardware that supports virtualization extensions, such as the case with AMD-V or Intel VT .
There are two parts to the KVM kernel modules: the core module ( kvm.ko ) and CPU architecture-specific modules ( kvm-intel.ko / kvm-amd.ko ). With KVM, the Linux kernel is the hypervisor, taking care of most of the heavy lifting. In addition, there are drivers such as the integrated Virtio that allow for I/O virtualization.
Today, hardware usually supports virtualization and KVM is already available, but in order to see if your system is capable of using KVM, you can do the following check (output edited):
$ grep 'svm\|vmx' /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb
rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology
tsc_reliable nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64
ds_cpl vmx tm2 ssse3 sdbg cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt
tsc_deadline_timer aes xsave rdrand lahf_lm 3dnowprefetch cpuid_fault cat_l2
ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust
smep erms mpx rdt_a rdseed smap clflushopt intel_pt sha_ni xsaveopt xsavec
xgetbv1 xsaves dtherm ida arat pln pts md_clear arch_capabilities
...
$ lsmod | grep kvm
kvm_intel 253952 0
kvm 659456 1 kvm_intel
Search for svm or vmx in the CPU information (note that it reports on a per-CPU basis, so if you have eight cores, you would see this flags block repeated eight times).
We see vmx is listed, so we’re good concerning hardware-assisted virtualization.
Here we check if the KVM kernel modules are available.
This tells us that we have the kvm_intel kernel module loaded, so we’re all set concerning KVM usage.
One modern way to manage KVMs is with Firecracker.
Firecracker
Firecracker is a VMM that can manage KVM instances. It is written in Rust and was developed at Amazon Web Services primarily for serverless offerings, such as AWS Lambda and AWS Fargate.
Firecracker is designed to safely run multitenant workloads on the same physical machine. The Firecracker VMM manages so-called microVMs that expose an HTTP API to the host, allowing you to launch, query, and stop the microVMs. It emulates network interfaces by using TUN/TAP devices on the host, and block devices are backed by files on the host, supporting Virtio devices.
From a security perspective, in addition to the virtualization discussed so far, Firecracker by default uses seccomp filters (see “seccomp Profiles” ) to limit the host system calls it can use. cgroups can also be used. From an observability point of view, you can gather logs and metrics from Firecracker, via named pipes.
With that we move on to modern Linux distributions that focus on immutability and leverage containers.
Modern Linux Distros
The most prominent traditional Linux distributions include the following:
-
The Red Hat family (RHEL, Fedora, and CentOS/Rocky)
-
The Debian-based family (Ubuntu, Mint, Kali, Parrot OS, elementary OS, etc.)
-
The SUSE family (openSUSE and Enterprise)
-
Gentoo
-
Arch Linux
These are all perfectly fine distros. Depending on your needs and preferences, you can choose from being fully in control and taking care of everything yourself (from installation to patching) to having a fully managed offering where the distro takes care of most of the tasks.
With the rise of containers, as discussed in “Containers” , the role of the host operating system has changed. In the context of containers, traditional package managers (see “Packages and Package Managers” ) play a different role: most base container images tend to be built from particular Linux distros, and dependencies are met within the containers with .deb or .rpm packages, while the container images package up all the application-level dependencies on top of them.
Further, making incremental changes to a system turns out to be a big challenge. This is especially true when you need to do it at scale, such as when you need to administrate a fleet of machines. Hence, for modern distros, the focus is increasingly on immutability. The idea is that any change in the configuration or code (think: a patch that fixes a security issue or a new feature) causes the creation of a new artifact, such as a container image that gets launched (in contrast to changing the running system).
When I say “modern Linux distros,” I mean distros that are container-centric, with immutability and auto-upgrading (pioneered by Chrome) front and center. Let’s have a look at some examples of modern distros.
Red Hat Enterprise Linux CoreOS
In 2013, a young start-up called CoreOS made CoreOS Linux (later renamed Container Linux) available. Its main features included a dual-partition scheme for system updates and the lack of a package manager. In other words, all apps would run as containers natively. In the ecosystem, a number of tools were developed that are still in use (such as etcd ; think: a distributed version of the /etc directory for configuration tasks).
After Red Hat acquired CoreOS (the company), it announced the intention to merge the CoreOS Linux with Red Hat’s own Project Atomic (that had similar goals). This merger led to Red Hat Enterprise Linux CoreOS (RHCOS) , which is not meant to be used on its own but in the context of the Red Hat Kubernetes distribution called OpenShift Container Platform.
Flatcar Container Linux
A little bit after Red Hat announced its plans around Container Linux, a German startup called Kinvolk GmbH (now part of Microsoft) announced that it would fork and continue to develop Container Linux under the new brand name Flatcar Container Linux .
Flatcar describes itself as a container-native, lightweight operating system with use cases in container orchestrators such as Kubernetes and IoT/edge computing. It continues the CoreOS tradition of auto-upgrades (optional with its own update manager, Nebraska ) and has a powerful yet simple-to-use provisioning utility called Ignition that enables you to have fine-grained control over boot devices (also used by RHCOS for that purpose). Further, there is no package manager; everything is running in containers. You can manage the life cycle of the containerized apps with systemctl on a single machine or more typically with Kubernetes.
Bottlerocket
Bottlerocket is a Linux-based operating system developed by AWS and meant for hosting containers . Written in Rust, it is used in a number of their offerings, such as Amazon EKS and Amazon ECS.
Akin to Flatcar and CoreOS, instead of a package manager, Bottlerocket uses an OCI image-based model for app upgrades and rollbacks. Bottlerocket uses a (by and large) read-only, integrity-checked filesystem based on dm-verity . To gain access (via SSH, although discouraged) and control Bottlerocket, it runs a so-called control container , in a separate containerd instance.
RancherOS
RancherOS is a Linux distro where everything is a container managed by Docker. Sponsored by Rancher (now SUSE), it is optimized for container workloads as in their Kubernetes distro. It runs two Docker instances: the system Docker, which runs as the first process, and the user Docker, which is used to create application containers. RancherOS has a small footprint, which makes it really great to use in the context of embedded systems and edge computing.
Selected Security Topics
In Chapter 4 , we discussed a number of access control mechanisms. We discussed authentication ( authn , for short), which verifies the identity of a user and is a precondition for any sort of authorization ( authz , for short). In this section, we briefly discuss two widely used authn tools that you should be aware of.
Kerberos
Kerberos is an authn suite developed by the Massachusetts Institute of Technology in the 1980s. Today, it’s formally specified in RFC 4120 and related IETF documents. The core idea of Kerberos is that we’re usually dealing with insecure networks, but we want a secure way for clients and services to prove their identity to one another.
Conceptually, the Kerberos authn process, shown in Figure 9-2 , works as follows:
Figure 9-2. Kerberos protocol concept
-
A client (for example, a program on your laptop) sends a request to a Kerberos component called the Key Distribution Center (KDC), asking for credentials for a given service, such as printing or a directory.
-
The KDC responds with the requested credentials—that is, a ticket for the service and a temporary encryption key (session key).
-
The client transmits the ticket (which contains the client’s identity and a copy of the session key) to the service.
-
The session key, shared by the client and service, is used to authenticate the client and may optionally be used to authenticate the service.
There are also challenges with Kerberos, such as the central role that the KDC plays (a single point of failure) and its strict time requirements (it requires clock synchronization between the client and the server via NTP). Overall, while not simple to operate and administrate, Kerberos is widely used and supported in the enterprise and cloud providers.
Pluggable Authentication Modules
Historically, a program would manage the user authentication process itself. With pluggable authentication modules (PAM) , a flexible way to develop programs that are independent of a concrete authentication scheme has arrived in Linux (PAM has been around since the end of the 1990s in the wider UNIX ecosystem). PAM uses a modular architecture, providing developers a powerful library to interface with it. It also allows system administrators to plug in different modules, such as the following:
Requires that a user is listed in /etc/passwd
For session keyrings
For Kerberos 5 password-based checks
With that, we’ve reached the end of the advanced security topics and now turn to more aspirational topics.
Other Modern and Future Offerings
In this section, we look at exciting Linux offerings, including new ways to set up Linux and ways to work with Linux in new environments. In the server world (be it an on-premises data center or the public cloud), Linux is already the de facto standard, and Linux is under the hood in many mobile devices.
What the topics here in this section have in common is that at the time of writing, they have not yet entered the mainstream. However, if you’re curious about what future developments might look like or where there’s still high growth potential for Linux, read on.
NixOS
NixOS is a source-based Linux distro, taking a functional approach to package management and system configuration as well as rollbacks for upgrades. I call this a “functional approach” because the artifacts are based on immutability.
The Nix package manager builds the entire operating system, from the kernel to system packages and apps. Nix offers multiuser package management and even allows you to install and use multiple versions of the same package.
Unlike most other Linux distros, NixOS does not follow the Linux Standard Base filesystem layout as discussed in “Common Filesystem Layouts” (with system programs located in /usr/bin , /usr/lib , and so on, and the configuration usually located in /etc ).
There are a number of interesting ideas in NixOS and its ecosystem, making it especially relevant for CI pipelines. Even if you don’t want to go all in, you can, for example, use the Nix package manager standalone (outside of NixOS).
Linux on the Desktop
While the viability of Linux on the desktop is subject to ongoing discussions, there is without doubt plenty of choice concerning desktop-friendly distros and with them a selection of window managers .
In good UNIX tradition, the Graphical User Interface (GUI) part is separated from the rest of the operating system. Usually, an X window manager takes care of the GUI responsibilities (from window management to styling and rendering) with the help of a display manager .
On top of the window manager, implementing a desktop experience (such as icons, widgets, and toolbars), sit the desktop environments , such as KDE or MATE.
There are many beginner-friendly desktop Linux distros available nowadays, making it easy to switch from Windows or macOS. The same is true for a range of open source applications, from office apps (writing docs or working with spreadsheets, such as LibreOffice) to drawing and image editing (Gimp), to all major web browsers, games, media players, and utilities, to development environments.
The catalyst for Linux on the desktop might in fact come from a rather unexpected direction: with Windows 11 allowing you to run graphical Linux apps out of the box, this might change the incentives and uptake for good. Time will tell.
Linux on Embedded Systems
Linux on embedded systems is a wide field, with implementations ranging from cars to networking equipment (such as routers), to smart home devices (for example fridges) and media devices/smart TVs.
One particularly interesting generic platform you can acquire for little money is a Raspberry Pi (RPI) . It comes with its own Linux distro called Raspberry Pi OS (a Debian-based system) and lets you install this and other Linux distros simply via a microSD card. The RPI has a number of General Purpose Input/Outputs (GPIOs), making it straightforward to use external sensors and circuits via a breadboard. You can experiment with, and learn electronics and program the hardware with, for example, Python.
Linux in Cloud IDE
In recent years, the viability of cloud-based development environments has made enormous progress to a point where now (commercial) offerings exist that combine an IDE (usually Visual Studio Code), Git, and a range of programming languages in a Linux environment. All you as a developer need is a web browser and network access, and you can edit, test, and run code “in the cloud.”
Two notable examples of Cloud IDEs, at the time of writing, are Gitpod , which is available either as a managed offering or as an open source to host yourself, and Codespaces , which is deeply integrated into GitHub.
Conclusion
This chapter covered advanced topics and refined your knowledge of basic techniques and tooling. If you want to enable IPC, you can use signals and named pipes. For isolating workloads, you can use VMs, especially modern variants such as Firecracker. We also discussed modern Linux distributions: if you plan to run containers (Docker), you may want to consider these container-centric distros that enforce immutability. We then moved on to selected security topics, specially Kerberos and PAM for flexible and/or large-scale authentication. Finally, we reviewed not-yet-mainstream Linux solutions such as Linux on the desktop and how you can get started with Linux on embedded systems, such as the Raspberry Pi, for local experimentation or development.
Some further reading for this chapter:
IPC
VMs
Modern distros
-
“Tutorial: Install Flatcar Container Linux on Remote Bare Metal Servers”
-
List of image-based Linux distributions and associated tooling
-
“Security Features of Bottlerocket, an Open Source Linux-Based Operating System”
Selected security
Other modern and future offerings
We’ve reached the end of the book. I hope this is the start of your own Linux journey. Thanks for staying with me, and if you have feedback, I’m always interested to hear from you, either via Twitter or via good old email: [email protected] .