The dog's anal glands produce a scent that is specific to the individual dog- kind of like fingerprints.
This is why dogs are also interested in sniffing other dog's poo- because when a dog poos the dog's scent also comes out of the anal gland and attaches itself to the poo- like a calling card.
When a dog smells another dog's butt they are sniffing the anal glands to identify the dog.
You have to remember that dogs aren't like people. They rely on their sence if sight least, unlike humans who use sight as the main way we recognise people and places.
Dogs have a sense of smell that makes ours look miniscule- and they use this fantastic ability to identify other dogs, people, places, sniff out food, water, etc.