I was walking with Thabit Bunani when he passed by some boys and greeted them. Thabit related that he had been walking with Anas when he passed by some boys and greeted them, and Anas related that he had been walking with the Messenger of Allah ﷺ when he passed by some boys and greeted them.
كنت أمشي مع ثابت البناني، فمر بصبيان فسلم عليهم، وحدث ثابت أنه كان يمشي مع أنس، فمر بصبيان فسلم عليهم، وحدث أنس أنه كان يمشي مع رسول الله ﷺ فمر بصبيان فسلم عليهم.
Bukhari narrated it in the Book of Seeking Permission (6247), and Muslim in the Book of Greetings (2168:15), both through the route of Shuba from Sayyar, who related it. The wording is Muslim's, and Bukhari did not mention what Thabit Bunani did. Nasai added, in his Sunan al-Kubra (8349), with a sahih chain through another route from Thabit from Anas, that the Messenger of Allah ﷺ used to visit the Ansar, greet their children with peace, stroke their heads, and pray for them. Greeting children with peace is not a sunnah, but is done for the sake of teaching.