The Messenger of Allah ﷺ said, "Whoever obeys me has obeyed Allah, and whoever disobeys me has disobeyed Allah. Whoever obeys the commander," and Waki said, "the imam, has obeyed me, and whoever disobeys the commander," and Waki said, "the imam, has disobeyed me."
حدثنا أبو معاوية ووكيع قالا حدثنا الأعمش عن أبي صالح
قال رسول الله ﷺ من أطاعني فقد أطاع الله ومن عصاني فقد عصى الله ومن أطاع الأمير وقال وكيع الإمام فقد أطاعني ومن عصى الأمير فقد عصاني وقال وكيع الإمام فقد عصاني
Its isnad is sahih, and it is a longer version of 7330. We explained there that Bukhari and Muslim both narrated it through more than one route. Ibn Majah narrated part of it under number 3, from Abu Bakr bin Abu Shayba, from Abu Muawiya and Waki, with this isnad. He then narrated it in full at 2859, from Abu Bakr bin Abu Shayba and Ali bin Muhammad, both from Waki alone, with this isnad.Professor Fuad Abdul-Baqi made an oversight when he said, regarding the first narration in Ibn Majah, that this hadith is something the author narrated alone. This is not correct, for Bukhari and Muslim both narrated it, as we have mentioned. Nasai also narrated it, 2:185, through the route of Zuhri, from Abu Salama, from Abu Hurairah.