Terminal command to find out if a server is virtual or physical

Under given conditions:

terminal command which doesn't require the executing user to be in the sudoers group and also to be universal and not requiring to install additional packages.

the obvious simplest method for unmodified VMs, which owners intentionally haven't tried to hide fact the OS is VM, is

cat /sys/class/dmi/id/product_name

More possibilities:

  • How to detect virtualization
  • 16 Methods To Check If A Linux System Is Physical or Virtual Machine

Outside of the given by OP author conditions there are more complicated approaches like this one: Where am I? Operating System and Virtualization Identification Without System Calls


This also requires systemd (which is pretty ubiquitous these days anyways), but systemd-detect-virt is a better tool to tell whether this is running on physical or virtual hardware.

You can take a look at the logic used by systemd-detect-virt, you'll notice that it actually looks at many places to detect several distinct virtualization technologies...

I think something naïve such as looking at lscpu output might work in some cases some of the time, but I think it would hardly work all the time. Also please note that many technologies make it possible (and even likely) for VMs to have more than one thread per core, so I don't even think that particular feature is sufficient to do any kind of reliable detection here.