I want make a system in which I can encrypt/decrypt something based on Hard Disk serial number so that key can't be shared across the computer.
-
I don't think that it will work on Unix based system – mik Feb 25 '15 at 19:10
-
Check out blkid(8) -- http://linux.die.net/man/8/blkid – user590028 Feb 25 '15 at 19:16
-
Look at this answer: http://stackoverflow.com/a/5482977/676877 – Brett Okken Feb 25 '15 at 20:46
1 Answers
How to get the serial number of a hard disk is different for every Unix variant.
For Linux, if you're running as root, the most direct way is to either use 'hdparm -i /dev/sda' or more correctly the C code (ioctl's) that it uses.
The serial numbers aren't generally useful in Linux so if you aren't running as root you have to interrogate one of the few subsystems that actually has a use -- udev. It uses the serial numbers to uniquely identify devices and stores this information under /run/udev/data ( or /var/run/udev/data) in a file with a name based on the device numbers assigned by Linux.
The data for the first disk found is in /var/run/udev/data/b8:0
the second is in /var/run/udev/data/b8:16
This is a text file.
BTW: The disk serial number is NOT a good encryption key, as you see it's easy to find and is no where as random as it might look.

- 2,261
- 15
- 15