First and foremost, always ask the owner. Not only is this polite of course, but they know their dogs temperament and current mood. They may also have rules they are training him to follow, like not wanting him to jump up.
Bear in mind that dogs on a leash may be more nervous, since they know they can’t back away if they feel unsure about you.
Get low. Don’t lean over or tower above their head, think how imposing this would be to you. Squat down.
Hold out your hands slowly and open, let them come to you and sniff. Of course they can smell you coming, but this gives them time to properly check you out – it’s about body language and energy not just scent.
Notice how human greetings in many different cultures involve showing your hands. Dogs also know that we use our hands to do things like pet them, feed them treats, but also grab or hit them. If they are likely to bite your hand off, you’ll know about it before you even get to this point.
They may be timid and make sudden movements, but try to stay still; don’t make sudden jerky movements forward or backward. Even when they move in to sniff you they may still not be entirely comfortable, so give them a few more seconds even when you think they are happy. Let them control the meeting. If they really don’t seem happy, don’t try to force it, just back off and wait until they “warm up” to you.
Once they seem to be happy, don’t go immediately for touching the top of their head. Start with an underhand approach, stroking their chest or chin. They can better see what you are doing and chances are will not feel threatened or vulnerable.
Avoid staring at the dog. Similar to cats, they might play the “blink and you lose” game.
Dogs are good at reading your body language and behavior, e.g. when walking calm and slowly is the best way to go about it.
They’ll also listen to your voice and the general tune. Are you sounding aggressive or not? So actually saying “Hello” in a higher, happy voice, might do more than any other thing you can think of.
Many dogs show others that they’re no danger and want to meet them by lying down and waiting. This most likely is out of question, so just standing still, bending and/or crouching might be enough. Keep in mind that dogs who are more dominant, fearful or unsure won’t do this right away being they might consider this a sign of submission and vulnerability.