Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:16609Abū Bakr Muḥammad b. al-Ḥasan b. Fūrak > ʿAbdullāh b. Jaʿfar al-Aṣbahānī > Yūnus b. Ḥabīb > Abū Dāwud > Shuʿbah > Zubayd > Saʿd b. ʿUbaydah > Abū ʿAbd al-Raḥman al-Sulamī > ʿAlī ؓ

[Machine] That the Prophet ﷺ sent out a military expedition and appointed a man in charge of them, commanding them to obey him. He kindled a fire for them and commanded them to enter it, so some people thought they should do it, while others said they had fled from the fire and refused. Then they came to the Messenger of Allah ﷺ and they told him about it. The Messenger of Allah ﷺ said, “If they had entered it, they would have remained in it until the Day of Resurrection, for there is no obedience in disobedience to Allah. Obedience is only in what is good.”  

البيهقي:١٦٦٠٩أَخْبَرَنَا أَبُو بَكْرٍ مُحَمَّدُ بْنُ الْحَسَنِ بْنِ فُورَكٍ أَنْبَأَ عَبْدُ اللهِ بْنُ جَعْفَرٍ الْأَصْبَهَانِيُّ ثَنَا يُونُسُ بْنُ حَبِيبٍ أَنْبَأَ أَبُو دَاوُدَ ثَنَا شُعْبَةُ عَنْ زُبَيْدٍ عَنْ سَعْدِ بْنِ عُبَيْدَةَ عَنْ أَبِي عَبْدِ الرَّحْمَنِ السُّلَمِيِّ عَنْ عَلِيٍّ ؓ

أَنَّ النَّبِيَّ ﷺ بَعَثَ سَرِيَّةً وَأَمَّرَ عَلَيْهِمْ رَجُلًا وَأَمَرَهُمْ أَنْ يُطِيعُوهُ فَأَجَّجَ لَهُمْ نَارًا وَأَمَرَهُمْ أَنْ يَقْتَحِمُوا فَهَمَّ قَوْمٌ أَنْ يَفْعَلُوا وَقَالَ آخَرُونَ إِنَّمَا فَرَرْنَا مِنَ النَّارِ فَأَبَوْا ثُمَّ قَدِمُوا عَلَى رَسُولِ اللهِ ﷺ فَذَكَرُوا لَهُ ذَلِكَ فَقَالَ رَسُولُ اللهِ ﷺ لَوْ دَخَلُوهَا لَمْ يَزَالُوا فِيهَا إِلَى يَوْمِ الْقِيَامَةِ لَا طَاعَةَ فِي مَعْصِيَةِ اللهِ إِنَّمَا الطَّاعَةُ فِي الْمَعْرُوفِ  

أَخْرَجَهُ الْبُخَارِيُّ وَمُسْلِمٌ فِي الصَّحِيحِ مِنْ حَدِيثِ غُنْدَرٍ عَنْ شُعْبَةَ

See similar narrations below:

Collected by Abū Dāwūd
abudawud:2625ʿAmr b. Marzūq > Shuʿbah > Zubayd > Saʿd b. ʿUbaydah > Abū ʿAbd al-Raḥman al-Sulamī > ʿAlī

‘Ali (Allaah be pleased with him) said “The Messenger of Allah ﷺ sent an army and appointed a man as a commander for them and he commanded them to listen to him and obey. He kindled fire and ordered them to jump into it. A group refused to enter into it and said “We escaped from the fire; a group intended to enter into it. When the Prophet ﷺ was informed about it, he said “Had they entered into it, they would have remained into it. There is no obedience in matters involving disobedience to Allaah. Obedience is in matters which are good and universally recognized.  

أبو داود:٢٦٢٥حَدَّثَنَا عَمْرُو بْنُ مَرْزُوقٍ أَخْبَرَنَا شُعْبَةُ عَنْ زُبَيْدٍ عَنْ سَعْدِ بْنِ عُبَيْدَةَ عَنْ أَبِي عَبْدِ الرَّحْمَنِ السُّلَمِيِّ عَنْ عَلِيٍّ ؓ

أَنَّ رَسُولَ اللَّهِ ﷺ بَعَثَ جَيْشًا وَأَمَّرَ عَلَيْهِمْ رَجُلاً وَأَمَرَهُمْ أَنْ يَسْمَعُوا لَهُ وَيُطِيعُوا فَأَجَّجَ نَارًا وَأَمَرَهُمْ أَنْ يَقْتَحِمُوا فِيهَا فَأَبَى قَوْمٌ أَنْ يَدْخُلُوهَا وَقَالُوا إِنَّمَا فَرَرْنَا مِنَ النَّارِ وَأَرَادَ قَوْمٌ أَنْ يَدْخُلُوهَا فَبَلَغَ ذَلِكَ النَّبِيَّ ﷺ فَقَالَ لَوْ دَخَلُوهَا أَوْ دَخَلُوا فِيهَا لَمْ يَزَالُوا فِيهَا وَقَالَ لاَ طَاعَةَ فِي مَعْصِيَةِ اللَّهِ إِنَّمَا الطَّاعَةُ فِي الْمَعْرُوفِ