Whenever we prayed behind the Messenger of Allah ﷺ, we would say "as-salamu alaykum" while gesturing with our hands to the right and to the left. The Messenger of Allah ﷺ said, "What is the matter with people who throw their hands about as if they were the tails of unruly horses? Let one of you remain still, place his hand on his thigh, and then give the greeting to his companion on his right and on his left."
حدثنا يزيد أخبرنا مسعر عن عبيد الله ابن القبطية
كنا إذا صلينا وراء رسول الله ﷺ قلنا السلام عليكم بأيدينا يمينا وشمالا فقال رسول الله ﷺ ما بال أقوام يرمون بأيديهم كأنها أذناب الخيل الشمس ألا يسكن أحدكم ويشير بيده على فخذه ثم يسلم على صاحبه عن يمينه وعن شماله
Its isnad is sahih. Abdullah bin Qibtiyyah was deemed trustworthy by Ibn Main and Ibn Hibban, and Muslim narrated from him, as did Bukhari in Rafu al-Yadayn. The hadith was narrated by Muslim, 1/322, no. 431, in the chapter on prayer, on salutation, and by Nasai, 3/4 and 5, in the chapter on inattentiveness in prayer, on saluting with the hands.