How to generate unique hardware hash?

Solution 1:

You could use the MAC address of eth0 (assuming this exists on each machine). You can get that on its own (there may be a simpler way) with this:

ifconfig eth0 | grep HWaddr | awk '{ print $NF}' | sed 's/://g'

That will give you something like 6cf04954aaaa.

These are supposed to be unique but they're not always. If all your network hardware comes from the same manufacturer, you might find some crossover, so be careful with it.


Failing that, you could generate your own unique string and store it in /etc/computer-id (or another path of your choosing).

uuidgen -r

Will generate something as random as possible eg: 52a85807-35fe-409e-8983-87eb58c02ece

uuidgen -t

Uses time and eth0's MAC to make something like: eb8280dc-b5ec-11e0-90dd-6cf04954aaaa

Both are fairly unique but, as with anything random, there is always the possibility of a clash. Keep a central list to avoid problems like this.

Solution 2:

The simplest solution I could think of is:

sudo dmidecode -s system-uuid

According to the manual page of dmidecode, this data is retrieved from the Desktop Management Interface which has something to do with the BIOS. It cannot be changed.

I tested this command on two machines with the same hardware and the result is different as expected from the name system-uuid, so it can actually be used as unique hardware hash.