Sub topic 1
Know What You Are Running: `/etc/os-release`
Before administering a Linux server, identify the distribution and release that are actually running. Commands and package names vary between distributions. Guessing from memory can lead to failed installations or incorrect security changes.
This chapter assumes you already know how to use a shell, install packages, work with systemd services, and explain the basic purpose of a firewall and user permissions.
Prerequisites
You should be comfortable with:
- Running commands in a terminal.
- Reading plain-text configuration files.
- Using
sudofor administrative commands. - Understanding that a distribution includes the Linux kernel, system tools, package tools, and software repositories.
Read `/etc/os-release`
/etc/os-release is a standard text file that describes the operating system. It normally exists on modern Linux distributions. It contains shell-compatible variable assignments, such as ID=ubuntu or VERSION_ID="24.04".
Read it without changing anything:
cat /etc/os-releaseTypical output from an Ubuntu server includes values like these:
NAME="Ubuntu"
VERSION="24.04.1 LTS (Noble Numbat)"
ID=ubuntu
ID_LIKE=debian
VERSION_ID="24.04"
PRETTY_NAME="Ubuntu 24.04.1 LTS"The most useful fields are:
| Field | Meaning | Example |
|---|---|---|
| `ID` | Machine-readable distribution identifier | `ubuntu` |
| `ID_LIKE` | Related distribution family, when provided | `debian` |
| `VERSION_ID` | Machine-readable release version | `24.04` |
| `PRETTY_NAME` | Human-readable distribution and release name | `Ubuntu 24.04.1 LTS` |
| `NAME` | Human-readable distribution name | `Ubuntu` |
The ID field identifies the specific distribution. The ID_LIKE field suggests compatibility with another distribution family. For example, Ubuntu usually reports ID=ubuntu and ID_LIKE=debian. Rocky Linux reports a Rocky or RHEL-compatible identity and commonly indicates the RHEL family.
Use these fields instead of parsing the human-readable PRETTY_NAME value. Human-readable text can change between releases, while scripts should rely on documented machine-readable fields.
A concise identification command is:
. /etc/os-release
printf '%s %s (ID=%s, family=%s)\n' \
"$NAME" "$VERSION_ID" "$ID" "${ID_LIKE:-unknown}"The dot command loads the file's variables into the current shell. The quotation marks preserve values that contain spaces. The ${ID_LIKE:-unknown} expression supplies unknown if the variable is missing.
Only source the standard operating-system file on a trusted host. Do not source an arbitrary file downloaded from the internet. If /etc/os-release does not exist, check /usr/lib/os-release, which is used by some systems:
if [ -r /etc/os-release ]; then
. /etc/os-release
elif [ -r /usr/lib/os-release ]; then
. /usr/lib/os-release
else
printf '%s\n' "Cannot identify the distribution" >&2
exit 1
fi
printf '%s\n' "${PRETTY_NAME:-$NAME}"Distribution Family and Administrative Consequences
A distribution family is a group of systems that share important package and administration conventions. Debian-based systems commonly use apt to manage packages and dpkg as the lower-level package database. RHEL-compatible systems commonly use dnf and rpm.
This relationship is useful, but it is not a complete compatibility guarantee. A package built for Debian is not automatically usable on Ubuntu, and a package built for one RHEL release may not be suitable for every Rocky Linux release.
Do not use uname -a as a replacement for /etc/os-release. uname describes the kernel and hardware architecture. It does not reliably identify whether the user space is Ubuntu, Debian, Rocky Linux, or another distribution.
Common Errors
- Checking the server image name instead of the running system. Cloned images and rebuilt hosts can have different identities.
- Assuming
ID_LIKEalways exists. Treat it as optional. - Selecting commands from a search result without checking the release. Repository names and package versions can differ.
- Assuming a familiar distribution has the same defaults. Firewall tools, mandatory access control, enabled services, and repository contents can vary.
Exercise
A host reports ID=ubuntu, ID_LIKE=debian, and VERSION_ID="24.04". Which package-management family should you expect, and what should you verify before installing software?
Show answer
Expect Debian-family tooling such as apt and dpkg. Verify that the configured repositories support Ubuntu 24.04 and that the software vendor supports this release.