Riyad as-Salihin (The Meadows of the Righteous)
by Imam Nawawi
133. Chapter: On the adab of the greeting
857. Abu Hurayra reported that the Messenger of Allah, may Allah bless him and grant him peace, said, "Someone riding should greet someone walking, and someone walking should greet someone sitting, and a small group should greet a larger group." [Agreed upon]
In a variant of al-Bukhari, "The young should greet the old."
858. Abu Umama Suda ibn 'Ajlan al-Bahili reported that the Messenger of Allah, may Allah bless him and grant him peace, said "The person closer to Allah is the one who initiates the greeting." [Abu Dawud]
At-Tirmidhi related from Abu Umama, "It was asked, 'Messenger of Allah, when two men meet which of them begins the greeting?' He said, 'The one who is closer to Allah Almighty.'"