Abu Hurayrah (may Allah be pleased with him) reported that the Prophet (may Allah's peace and blessings be upon him) said: "The one who is riding should greet the one who is walking, the one who is walking should greet the one who is sitting, and the small group of people should greet the large one.''
شرح الحديث :
This Hadīth instructs Muslims as to who should initiate the greeting of peace when people meet: 1. A person riding should greet a person on foot, because the one riding is in a higher position than the one on foot, so initiating the greeting on his part is a sign of humbleness towards his fellow Muslim at a time when he is physically higher than him. This is something that earns him the love and affection of his Muslim brother. 2. A person walking should greet a person who is seated, since the one walking resembles someone entering a house and greeting those inside it. Another wisdom behind it is that it may be difficult for the seated person to stand every time someone passes by him. Therefore, he is not required to initiate the greeting so as to spare him such difficulty. 3. A small group of people should greet a larger group as a sign of respect to the larger group. 4. A young person should greet the older one, because the older has a right over the younger person. However, if the small group are inattentive and do not initiate the greeting, then the larger group should greet them. Likewise, if the young person is inattentive, the older one should greet him, in order to uphold this act of Sunnah. The statement of the Prophet (may Allah's peace and blessings be upon him) does in no way mean that it is forbidden for the older to greet the younger. Rather, the correct meaning is that the younger person should greet the older person, but if he fails to do this, then the older should start the greeting. This is based upon the Hadīth reported by Abu Umāmah (may Allah be pleased with him): "The most worthy (of the favor) of Allah are those who initiate the greeting of peace." Thus, if two Muslims meet, the one most worthy of Allah's favor is the one who greets the other first. According to another Hadīth: "... and the best of the two is the one who gives the greeting first."