Best way to get machine id on Linux?

后端 未结 4 1183
一整个雨季
一整个雨季 2020-12-08 05:04

What is the best-practiced way to get an unique machine ID in GNU/Linux for i386 architecture?

Are there any good ways except the mac

相关标签:
4条回答
  • 2020-12-08 05:22

    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.

    0 讨论(0)
  • 2020-12-08 05:26

    On modern machines with systemd machine id is created by systemd-machine-id-setup and it's location is more standard and with standardized format. Just:

    cat /etc/machine-id
    
    0 讨论(0)
  • 2020-12-08 05:29

    A simple and portable way of computing your own sysid may be to serialize uname(), gethostid() and some inodes like /home or your application homedir (obtained with stat()) etc. in a string and hash It.

    0 讨论(0)
  • 2020-12-08 05:37

    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
    ...
    
    0 讨论(0)
提交回复
热议问题