Mishkat al-Masabih 254
عَنْ أَبِي هُرَيْرَةَ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «إِنَّ مِمَّا يَلْحَقُ الْمُؤْمِنَ مِنْ عَمَلِهِ وَحَسَنَاتِهِ بَعْدَ مَوْتِهِ عِلْمًا علمه ونشره وَولدا صَالحا تَركه ومصحفا وَرَّثَهُ أَوْ مَسْجِدًا بَنَاهُ أَوْ بَيْتًا لِابْنِ السَّبِيلِ بَنَاهُ أَوْ نَهْرًا أَجْرَاهُ أَوْ صَدَقَةً أخرجهَا من مَاله فِي صِحَّته وحياته يلْحقهُ من بعد مَوته» . رَوَاهُ بن مَاجَه وَالْبَيْهَقِيّ فِي شعب الْإِيمَان
From Abu Hurayrah, who said: The Messenger of Allah ﷺ said: "Among the deeds and good works that reach the believer after his death are: knowledge that he taught and spread, a righteous child he left behind, a copy of the Quran he left as inheritance, or a mosque he built, or a house he built for the wayfarer, or a stream he made flow, or charity he gave from his wealth while he was healthy and alive; it reaches him after his death." Reported by Ibn Majah, and al-Bayhaqi in Shuʿab al-Iman.