Ubuntu – I need a command to create a unique fingerprint from unix machine

shellshell-scriptingUbuntuunix

I need to create a serial number for my application in a Unix machine.

  1. The generated serial number should be unique
  2. Do not change over time (Only changes after hard drive or mother
    board changes)
  3. Do not need root privilege.

I found that, in Ubuntu there are some information about hard drives under the following folder:

/dev/disk/by-id

These files seem to be serial numbers of attached hard disks to the machine. I want to use the following command to generate a unique finger print of the machine.

ls /dev/disk/by-id | grep  -v 'part'

Is this possible? Does this command meets the conditions I specified above?

Best Answer

A good method to uniquely identify a machine is by SMBios UUID value. In linux, it can be accessed using the dmidecode tool.

# dmidecode -s system-uuid 1E00CBE0-008C-5900-FBCE-C86000B2350B

Another alternative, would be to use the UUID of the root file system. File-system UUID's can be accessed in "/dev/disks/by-uuid". This has the advantage of not requiring root privileges.

Yet another method is using blkid:

rootNode="$(mount | grep " / ")"; blkid -s UUID -o value ${rootNode%% *}

Related Topic