DEV Community

dpm_bush
dpm_bush

Posted on Originally published at sshflow.com

Check Linux Version the Right Way: Distro vs. Kernel

When someone asks which Linux version a machine is running, they may mean the distribution release or the kernel. Those are different values, and checking the wrong one can send troubleshooting or compatibility work in the wrong direction.

For the distribution and release, run:

cat /etc/os-release
Enter fullscreen mode Exit fullscreen mode

For the kernel currently running, run:

uname -r
Enter fullscreen mode Exit fullscreen mode

Distribution version and kernel version answer different questions

The distribution is the packaged operating system: Ubuntu, Debian, Fedora, Rocky Linux, and others. Its release might be Ubuntu 24.04 or Debian 12.

The kernel is the lower-level component the operating system runs on. It has its own version, such as 6.8.0-45-generic.

These versions don’t move in lockstep. Two systems on the same distribution release can have different kernels after different updates. And the same kernel line can appear on more than one distribution.

A useful rule of thumb:

  • Checking package or OS compatibility? Identify the distribution and release.
  • Investigating a driver or kernel-level issue? Check the running kernel.

Identify the distribution

/etc/os-release is the best first check on most current Linux systems:

cat /etc/os-release
Enter fullscreen mode Exit fullscreen mode

You’ll see fields similar to these:

PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
Enter fullscreen mode Exit fullscreen mode

For a quick human-readable answer, look at PRETTY_NAME. For scripts, use ID and VERSION_ID: the format of PRETTY_NAME is intended for people and isn’t guaranteed to stay consistent enough for parsing. ID_LIKE indicates a distribution family; it can be useful when a script needs to recognize related distributions, but it isn’t a substitute for the actual distribution ID.

To print just the fields often needed in a script:

grep -E '^(ID|VERSION_ID)=' /etc/os-release
Enter fullscreen mode Exit fullscreen mode

Or read the file’s variables into a shell:

. /etc/os-release
echo "$ID $VERSION_ID"
Enter fullscreen mode Exit fullscreen mode

If you use this approach, treat the file as system configuration and only source it from the machine you intend to inspect.

Check the running kernel

Use uname -r for the kernel release alone:

uname -r
Enter fullscreen mode Exit fullscreen mode

For more details, including the hostname, build information, and architecture, use:

uname -a
Enter fullscreen mode Exit fullscreen mode

The longer output is useful when you need architecture or build details, but it includes more information than most version checks require. For the kernel release, uname -r is usually the clearest answer.

On a system using systemd, hostnamectl can display distribution, kernel, and architecture together:

hostnamectl
Enter fullscreen mode Exit fullscreen mode

Check the Operating System, Kernel, and Architecture lines. If hostnamectl is unavailable or fails, use /etc/os-release for the distribution check and uname -r for the kernel check instead.

Run the checks on a remote server

You don’t need to open an interactive shell to check a remote machine. Run a command over SSH and print its output locally:

ssh user@host "cat /etc/os-release"
ssh user@host "uname -r"
Enter fullscreen mode Exit fullscreen mode

This is handy when confirming a server’s OS before installing software or comparing machines during an investigation. For more examples of running commands remotely, see this guide to the OpenSSH command and its options.

You can also combine the two checks into one remote command:

ssh user@host 'cat /etc/os-release; uname -r'
Enter fullscreen mode Exit fullscreen mode

The first command reports the distribution information; the second reports the active kernel release. If you’re setting up a new Ubuntu server and want the broader context around its OS and remote access, see this Ubuntu Server setup guide.

If a version-check command isn’t available

If lsb_release -a returns command not found, that doesn’t mean the system has no distribution information. lsb_release is often absent from minimal installations. Try the built-in release file first:

cat /etc/os-release
Enter fullscreen mode Exit fullscreen mode

Older systems may also have distribution-specific files. For example, /etc/debian_version can provide a Debian version number, while /etc/redhat-release can confirm a RHEL-family distribution. Treat these as fallbacks; on current systems, start with /etc/os-release.

If you only need the kernel version, don’t install a distribution-reporting tool: uname -r provides that separate value directly.

Quick reference

What you need Command
Distribution and release cat /etc/os-release
Kernel release currently running uname -r
Kernel and additional system details uname -a
Distribution and kernel together on systemd hostnamectl

The key distinction is simple: use /etc/os-release to identify the Linux distribution and its release, and uname -r to identify the kernel currently running.

I originally published a more detailed version of this guide on the SSHFlow blog.

I'm also building SSHFlow — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.

Top comments (0)