How to get motherboard ID on Linux from a C++ program
Solution 1
You don't have to be root to get the information, but you do need to have root first give you permission. Obviously root is allowed to secure access to their machine, and this includes access to hardware identity information.
root controls what the software on their machine can do, your software does not restrict what root can do. (Linux Corollary to The #1 Law of Software Licensing)
If root chooses to install your hardware id collector, it's relatively straightforward to make that data available to non-root users (but it's also relatively easy for root to modify your id collector to lie).
Solution 2
$ lshal | grep 'system\.hardware\.serial'
system.hardware.serial = '<serial-number>' (string)
Works as non-root user on FC11.
Solution 3
lshw should get the serial for you. It will tell you it should be run as superuser but will run anyway. (tested on ubuntu)
Solution 4
sudo dmidecode --type baseboard
Alexey
Updated on June 16, 2022Comments
-
Alexey almost 2 years
I want to retrieve motherboard ID from a C++ program on Linux (Ubuntu) without root privileges. I know that dmidecode can do this, but it requires root privileges, so it is not suitable for my needs. Does anyone know of non-root alternatives? Source code will be much appreciated.
-
Alexey over 13 yearsOK, but I can retrieve information about HDD (ATA) serial, MAC address or even CPU ID without root permissions. Why motherboard serial would be so special that there is no workaround?
-
John Zwinck over 13 yearsMAC address is useful for "normal" programming purposes, such as when you need to know what address another computer should tag a wake-on-lan "magic packet" with, or for other low-level networking functions. As for the ATA HDD serial number, maybe Linux will decide to limit that to privileged users too (I think this could be a good idea, actually). The CPU ID is useful for programs that have optimized code for specific processors. Motherboard serial numbers have no such use in normal code.
-
Ben Voigt over 13 years@Alexey: As John alludes to, CPUID describes capabilities, it is not a unique identifier like the motherboard serial number is.
-
Alexey over 13 yearsI tried it before, but it looks like Motherboard serial is returned only if lshw is started as root
-
Tomasz Gandor about 10 yearsVery nice command, however the returned serial (BSN12345678901234567) looks a bit improbable... (also - only as root, run as user misses serials or says "UNCLAIMED").
-
Tarick Welling almost 5 yearsWhat is FC11 and what to do when
lshal
is not available?