It is narrated from Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When the imam says 'Sami'allahu liman hamidah' (Allah has heard the one who praised Him), then say: 'Allahumma rabbana lakal-hamd' (O Allah, our Lord, to You belongs all praise); for whoever's words coincide with the words of the angels, all his past sins will be forgiven."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2617
(a) It is narrated from Hittan bin Abdullah al-Raqashi that Abu Musa al-Ash'ari (may Allah be pleased with him) led the people in prayer, and he then mentioned the complete hadith. In it there is also that Abu Musa al-Ash'ari (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings be upon him) addressed us, taught us the prayer and explained its method to us. He (peace and blessings be upon him) said: "When you stand to pray, straighten your rows. When the imam says the takbir, say the takbir; and when he says 'Not of those who have earned anger, nor of those who go astray' [Surah al-Fatihah: 7], say 'Amin'; Allah will answer your supplication. And when he says the takbir and bows, then bow, for the imam says the takbir before you and will also raise his head from bowing before you." And the Prophet (peace and blessings be upon him) said: "The follower should keep pace with him. And when the imam says 'Sami'allahu liman hamidah' (Allah has heard the one who praised Him), say 'Rabbana lakal-hamd' (Our Lord, to You belongs all praise); Allah will answer your supplication."
(b) It is narrated from Zahdam al-Jarmi: I prayed behind Sayyiduna Abu Musa al-Ash'ari (may Allah be pleased with him) and he said to us: When the imam says 'Allahu akbar', then you too, following him, say 'Allahu akbar'; and when he says 'Sami'allahu liman hamidah' while raising his head from bowing, then you too say the like of it.
The authentic narration is the first one.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2618
It is narrated from Sayyiduna Anas bin Malik (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) mounted a horse and fell from it, and his (peace and blessings be upon him) blessed right side was grazed. He (peace and blessings be upon him) led us in one of the prayers sitting, and we too prayed behind him (peace and blessings be upon him) sitting. When he (peace and blessings be upon him) finished the prayer, he said: "The imam is appointed only to be followed. Do not differ from the imam. When he leads the prayer standing, pray standing; when he says the takbir, say the takbir; when he says 'Sami'allahu liman hamidah' (Allah has heard the one who praised Him), say 'Rabbana wa lakal-hamd' (Our Lord, and to You belongs all praise); when he prostrates, prostrate; and when the imam leads the prayer sitting, pray sitting."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2619
It is narrated from Sayyiduna Abdullah (may Allah be pleased with him): "When the imam says 'Sami'allahu liman hamidah' (Allah has heard the one who praised Him), those following him should say 'Rabbana lakal-hamd' (Our Lord, all praise belongs to You)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2620