sudo dmidecode | grep "Serial Number"

You get something like this:

Serial Number: 21XHTN1