Abu Hurairah (May Allah be pleased with him) reported:
The Messenger of Allah (ﷺ) said, 'A rider should greet a pedestrian; a pedestrian should greet one who is sitting; and a small group should greet a large group (of people).''
[Al-Bukhari and Muslim].
The narration in Al-Bukhari adds: The Messenger of Allah (ﷺ) said, "The young should greet the elderly.''