[Machine] The Prophet ﷺ used to teach us words to say before sleeping out of fear. "In the name of Allah, I seek refuge in the perfect words of Allah from His anger, punishment, evil slaves, and from the whispers of devils and their presence." Abdullah bin Amr used to teach it to those of his sons who had reached the age of understanding, and he would write it for those who were still young and put it on their necks.
كَانَ رَسُولُ اللهِ ﷺ يُعَلِّمُنَا كَلِمَاتٍ نَقُولُهُنَّ عِنْدَ النَّوْمِ مِنَ الْفَزَعِ بِسْمِ اللهِ أَعُوذُ بِكَلِمَاتِ اللهِ التَّامَّة مِنْغَضَبِهِ وَعِقَابِهِ وَشَرِّ عِبَادِهِ وَمِنْ هَمَزَاتِ الشَّيَاطِينِ وَأَنْ يَحْضُرُونِ قَالَ فَكَانَ عَبْدُ اللهِ بْنُ عَمْرٍو يُعَلِّمُهَا مَنْ بَلَغَ مِنْ وَلَدِهِ أَنْ يَقُولَهَا عِنْدَ نَوْمِهِ وَمَنْ كَانَ مِنْهُمْ صَغِيرًا لَا يَعْقِلُ أَنْ يَحْفَظَهَا كَتَبَهَا لَهُ فَعَلَّقَهَا فِي عُنُقِهِ