Abu Hurairah reported,

He heard the Messenger of Allah ﷺ say, "Whoever obeys me has obeyed Allah, and whoever disobeys me has disobeyed Allah. Whoever obeys the commander has obeyed me, and whoever disobeys the commander has disobeyed me. The leader is but a shield, from behind whom people fight and by whom they are protected. If he commands the fear of Allah and rules justly, he has his reward for that, but if he commands otherwise, the burden of it falls upon him."

Bukhari 2957

Sahih

وبهذا الإسناد من أطاعني فقد أطاع الله ومن عصاني فقد عصى الله ومن يطع الأمير فقد أطاعني ومن يعص الأمير فقد عصاني وإنما الإمام جنة يقاتل من ورائه ويتقى به فإن أمر بتقوى الله وعدل فإن له بذلك أجرا وإن قال بغيره فإن عليه منه

البخاري 2957صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Jihad and expeditions
Chapter
Fighting from behind the imam and seeking protection through him
Numbering
Darussalam 2957
Bukhari 2957