Best way to get machine id on Linux?
On modern machines with systemd: machine id is created by systemd-machine-id-setup. The location of machine id is documented - in freedesktop machine-id and man machine-id and machine id has a more standardized format - see RFC4122. Just:
cat /etc/machine-id
You can use lshal. This needs hal (apt-get install hal or yum install hal) to be installed first. This way you can access all the info of dmidecode without root permissions.
A non-root equivalent of
# dmidecode | grep -i uuid
will be
$ lshal |grep -i system.hardware.uuid
And similarly other info as per your needs.
Depending on your kernel, the DMI information may be available via sysfs. Try those:
# cat /sys/class/dmi/id/board_serial
xxxxxxxxxxxxxxx
# cat /sys/class/dmi/id/product_uuid
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
or using a tool
# dmidecode -s baseboard-serial-number
...
# dmidecode -s system-uuid
...