عن أبي هريرة رضي الله عنه أَن النبيَّ -صَلّى اللهُ عَلَيْهِ وسَلَّم- قَالَ: «الرَّجُلُ عَلَى دِينِ خَلِيلِهِ، فَلْيَنْظُر أَحَدُكُم مَنْ يُخَالِل».
[حسن] - [رواه أبوداود والترمذي وأحمد]
Abu Hurayrah (may Allah be pleased with him) reported that the Prophet (may Allah's peace and blessings be upon him) said: "A man follows the religion (i.e. ways and manners) of his intimate friend. So, each of you should carefully consider whom he takes as his intimate friend."
Hasan/Sound. - [At-Tirmidhi]
The Hadīth of Abu Hurayrah (may Allah be pleased with him) teaches us that a person often adopts the habits, ways, and attitudes of his companion. So, in order to safeguard his religion and morals, one must scrutinize and consider the one whom he befriends. He should befriend the one whose religion and morals are pleasing to him; otherwise, he should not. Indeed, characters tend to steal (take over the characters of others), and companionship has an effect on reforming or corrupting the person's state. Al-Ghazāli said: "Socializing and mixing with a greedy person stimulates greediness. Likewise, socializing with and befriending an ascetic person urges one to adopt asceticism and abstention regarding the pleasures of the worldly life. That is because innate characters are naturally disposed to imitate and copy the characters of others inadvertently." In brief, this Hadīth proves that one should take only good people as companions, due to the good resulting from doing that.