Always walk your dog on a leash. Keep your hands at your sides. Allow the dog to sniff you before you reach to pet him. Before petting someone else's dog, ask for the owner's permission. Spend time playing with your dog.
Pets often guard their food, their babies, and their toys.
A dog's natural instinct is to chase after something that's running away. Instead, stand very still, let the dog sniff you, and continue to be still and quiet until the dog goes away. Instead, tell an adult about the animal. Unneutered dogs are generally more aggressive and prone to bite. A hug around a dog's neck seems like a nice thing to do, but to a dog this can be perceived as very threatening.