That was the way I was taught too, but it is, in fact, very confrontational to the dog.
If we get down to dog height and ask someone to perform the same gesture to us, it can immediately be seen how threatening it appears.
The best way to greet a strange dog is to ignore it totally.
Most dogs will approach of their own accord and sniff at our ankles, then either back off if they do not want further interaction, or else push against us or thrust their heads under our hands if they would like to be touched.
Some dogs are immediately friendly, while others like to take their time to do this, and the latter kind can approach and retreat several times before they invite any contact from us, if they invite it at all.
When we do touch them, it should not be on the head, and we should not pat the dog.
Instead, a gentle scratch on the chest or side is the best approach.