We went out with the Messenger of Allah ﷺ while we were young men with no means. He said, "Young men, you must marry, for it lowers the gaze and guards the private parts. Whoever cannot do so should fast, for fasting is a shield for him."
أخبرنا محمود بن غيلان قال حدثنا أبو أحمد قال حدثنا سفيان عن الأعمش عن عمارة بن عمير عن عبد الرحمن بن يزيد
خرجنا مع رسول الله ﷺ ونحن شباب لا نقدر على شيء قال يا معشر الشباب عليكم بالباءة فإنه أغض للبصر وأحصن للفرج ومن لم يستطع فعليه بالصوم فإنه له وجاء
It was narrated by Bukhari, chapter on Marriage, chapter titled "Whoever cannot afford marriage should fast," hadith no. 5066, and Muslim, chapter on Marriage, chapter titled "The recommendation of marriage for one whose soul longs for it," hadith no. 3/1400, from the hadith of Amash, and Tirmidhi, hadith no. 1081, from Mahmud bin Ghaylan with the same wording, and it is also found in Al-Kubra, hadith no. 2547.