Skip to content
Advertisement

Extract the Linux serial number without sudo

It is possible to extract the Linux serial number without using sudo?

I know it is possible to do in Windows: wmic bios get serialnumber and in macOS: system_profiler | grep "r (system)". Both of them do not require root privileges.

In Linux this can be used: sudo dmidecode -s system-serial-number, but it needs sudo. Is there another way?

Advertisement

Answer

dmidecode reads this information from physical memory, using /dev/mem, which requires root.

The same information is also provided by the Linux kernel via sysfs in a virtual directory, /sys/devices/virtual/dmi/id.

Unfortunately, someone decided that all information in that virtual directory is open to anyone for reading, just not the serial numbers:

JavaScript

If you can install package hal (not installed by default on recent Ubuntu versions), this command will work for you as non-root:

JavaScript

This works because package hal installs the hald daemon, which runs as root and collects this data, making it possible for lshal to read it as non-root.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement