Finding your Linux distribution and OS info#
The first question you ask when you SSH into a server for the first time, or inherit a setup you know nothing about, is this: what distribution is this, what version, how long since it was last updated? The answer is not in one single command - it lives in a few places, and which one you check depends on what you actually need to know.
The shortcut
If you have connected VeriTeknik MCP to your AI assistant (Claude, ChatGPT, Cursor...), just ask:
"Which distribution, version and kernel is web-01 running?"
Your assistant runs hostnamectl on the server and reads you the answer. The connection needs the Servers: execute tasks group for this; the command it runs only reads.
The fast answer: hostnamectl#
hostnamectl
On most modern systemd-based distributions (Ubuntu 16.04+, Debian 9+, RHEL/CentOS/Rocky/AlmaLinux 7+), one command gives you the distro name, version, kernel and architecture together. Look at the "Operating System" line near the top of the output.
Distro identity: /etc/os-release#
If hostnamectl is not available (or you want machine-readable output for a script), go straight to the source:
cat /etc/os-release
NAME="Ubuntu"
VERSION="24.04.1 LTS (Noble Numbat)"
ID=ubuntu
ID_LIKE=debian
VERSION_ID="24.04"
The ID and VERSION_ID fields are what you want for scripted if branches - far more reliable than grepping the distro name, because the format has barely changed since 2012, when systemd introduced the os-release standard.
Don't forget ID_LIKE
Rocky Linux sets ID=rocky but ID_LIKE="rhel centos fedora". A script deciding whether it is in the RHEL family or the Debian family usually checks ID_LIKE rather than ID - otherwise you need a new case branch for every new derivative distro.
Kernel and architecture#
uname -a
Linux server 6.8.0-51-generic #52-Ubuntu SMP x86_64 GNU/Linux
In order: hostname, kernel version, build date/number, architecture (x86_64, aarch64). If you only want the kernel version, uname -r is enough.
Virtual or physical#
systemd-detect-virt
Returns a virtualization technology like kvm, vmware, xen, lxc, or none for bare metal. On a VeriTeknik VPS the expected answer is kvm; this one line settles "is this virtual or real hardware" when you are diagnosing a hardware issue.
From a script: detecting the distro in one shot#
Writing an install script that needs to branch on package manager:
#!/usr/bin/env bash
source /etc/os-release
case "$ID" in
ubuntu|debian) echo "apt-based: $PRETTY_NAME" ;;
rocky|almalinux|rhel|centos) echo "dnf-based: $PRETTY_NAME" ;;
*) echo "unknown distro: $PRETTY_NAME" ;;
esac
To also catch derivative distros via ID_LIKE:
source /etc/os-release
if [[ "$ID_LIKE" == *debian* || "$ID" == "debian" ]]; then
echo "Debian family"
fi
With Morpheus
"what distribution and version is this server running"
Morpheus reads /etc/os-release and uname -a and summarizes it in one sentence - it can also check for packages with pending updates.
Commands people mix up#
| Command | Gives you | When to use it |
|---|---|---|
hostnamectl |
Distro + version + kernel + arch, human-readable | Quick overview |
cat /etc/os-release |
Machine-readable distro identity | Branching inside a script |
uname -r |
Kernel version only | Kernel module/compatibility checks |
lsb_release -a |
Older but still common; missing on some minimal images | Habit on Debian/Ubuntu derivatives |
systemd-detect-virt |
Virtualization technology, or none |
Hardware/performance diagnosis |
Checklist#
- [ ]
hostnamectlshows the distro name and version - [ ] Scripts read
$IDfrom/etc/os-releaseinstead of grepping the distro name - [ ]
uname -rmatches the kernel version you expect