Jami` at-Tirmidhi, Book 22, Hadith 29 (In-Book)

Narrated Abu Musa: "The Messenger of Allah was asked about a man who fights out of bravery, one who fights out of protection (for himself or others), and one who fought to be seen. Which of them is in the cause of Allah ? He said: 'Whoever fought so that the Word of Allah is supreme, then he is in Allah's cause.'" [Abu 'Eisa said:] There is something on this topic from 'Umar. This Hadith is Hasan Sahih.

حَدَّثَنَا هَنَّادٌ، حَدَّثَنَا أَبُو مُعَاوِيَةَ، عَنِ الأَعْمَشِ، عَنْ شَقِيقِ بْنِ سَلَمَةَ، عَنْ أَبِي مُوسَى، قَالَ سُئِلَ رَسُولُ اللَّهِ صلى الله عليه وسلم عَنِ الرَّجُلِ يُقَاتِلُ شَجَاعَةً وَيُقَاتِلُ حَمِيَّةً وَيُقَاتِلُ رِيَاءً فَأَىُّ ذَلِكَ فِي سَبِيلِ اللَّهِ قَالَ ‏ "‏ مَنْ قَاتَلَ لِتَكُونَ كَلِمَةُ اللَّهِ هِيَ الْعُلْيَا فَهُوَ فِي سَبِيلِ اللَّهِ ‏" ‏ ‏.‏ قَالَ أَبُو عِيسَى وَفِي الْبَابِ عَنْ عُمَرَ ‏.‏ وَهَذَا حَدِيثٌ حَسَنٌ صَحِيحٌ ‏.‏

sunnah.com