I asked, "Messenger of Allah, regarding our private parts, what may we expose and what must we cover?"He replied, "Guard your private parts from everyone except your wife or those your right hand possesses."I asked, "Messenger of Allah, what if people are together among one another?"He said, "If you can ensure that no one sees them, then do not let anyone see them."I asked, "Messenger of Allah, what if one of us is alone?"He answered, "Allah is more deserving of modesty before Him than people are."
حدثنا أبو بكر بن أبي شيبة حدثنا يزيد بن هارون وأبو أسامة قالا حدثنا
قلت يا رسول الله عوراتنا ما نأتي منها وما نذر قال احفظ عورتك إلا من زوجتك أو ما ملكت يمينك قلت يا رسول الله أرأيت إن كان القوم بعضهم في بعض قال فإن استطعت أن لا تريها أحدا فلا ترينها قلت يا رسول الله فإن كان أحدنا خاليا قال فالله أحق أن يستحيا منه من الناس
Its chain of transmission is hasan. Abu Dawud narrated it in the chapter on the hammam, section on being naked, hadith 4017, from the hadith of Bahz through this same route, and Tirmidhi graded it hasan, hadith 2769, and Bukhari referenced it without a full chain in his Sahih, in the book of ghusl, in the chapter on one who performs ghusl naked, alone, in private.