One of the most popular feature of nmap is its Operating System detection from network packets values. To get reliable detection result at least one port of the target should be open.
Enable Operating System Detection
Operating system (OS) detection can be enable with -O . On the other side -A parameter also provides operating system information. To use operating system detection nmap command should be run with root privileges because lower layer network manipulation will be done by nmap.
$ sudo nmap -O localhost
As we see in the example nmap successfully detected the operating system as Linux and the kernel version is 3 or 4 which is correct.