From Sahih Bukhari (Hadith 6233):
Narrated Abu Huraira: Allah's Messenger (ﷺ) said, "The riding person should greet the walking one, and the walking one should greet the sitting one, and the small number of persons should greet the large number of persons
Reference: Bukhari 6233