Linux hard drive serial number as non-root

Solution 1:

On most current distributions HDD serial numbers are stored in the udev database, which could be queried without root permissions:

/sbin/udevadm info --query=property --name=sda

(look for ID_SERIAL, ID_SERIAL_SHORT; there are also /dev/disk/by-id/ata-* symlinks for ATA drives based on those values).

udisks provides a higher-level interface to those data and more (it also gives access to SMART attributes without requiring root privileges, which would be needed for calling, e.g., smartctl directly).

Solution 2:

Another way that usually works is:

ls -l /dev/disk/by-id/

Here's a one liner that gives you a quick enumeration of drive and model/serial number:

ls -l /dev/disk/by-id/ | grep scsi- | grep -v part | awk '{print $NF " " $(NF-2)}' | sed 's|../../||g' | sed 's/scsi-...._//g'  

Or for remote machines:

ssh $host "ls -l /dev/disk/by-id/ | grep scsi- | grep -v part | awk '{print \$NF \" \" \$(NF-2)}' | sed 's|../../||g' | sed 's/scsi-...._//g'"

You can then further process this output. For most drive types, the second string per line is MODEL_SERIAL.