“… Know that not everyone is suited to be your friend. The Prophet (sallallahu `alayhi wa sallam) said, “A person is upon the Deen of his friend, so let each of you look to whom you befriend.” (Abu Dawud, 4833)
One must consider a number of characteristics (when choosing a friend):
He must be intelligent and sound of mind (astute) and generous among the people and he should not be an immoral person or an innovator or someone who desires and covets this world.
As for astuteness, then that is the capital. As ‘Ali (radhi’Allahu `anhu) said:
“Do not accompany the ignorant,
Beware of him, beware of him!
For how many of an ignorant one has destroyed,
A forbearing one when he goes to him.
A person is only weighed against another,
When he sides and walks with him.
And for everything there are indeed,
Similarities and a comparison.
Just like there is between two hearts,
A sign and an indication, when they do meet.”
So how will the matter be (for you) when the foolish ends up harming you although he intends to benefit you! For this reason, the poet said:
“I feel safe from an enemy who’s endowed with sound intellect ,
But I fear a friend who has been seized with mental illness.
For soundness of mind is of one type; I know its ways
But insanity manifests itself in so many numerous ways.”
For this reason, it is said: ‘Severing ties with the foolish means to draw closer to Allah, the Most High.’ Likewise, there is no good in the companionship of an immoral person because the one who fears Allah will never persist in a major sin, but as for him who does not fear Allah, then nobody is safe from the havoc he causes.
“… And do not obey one whose heart We have made heedless of Our remembrance and who follows his desire and whose affair is ever [in] neglect.” (al-Kahf: 28)
Taken from Imam al-Ghazali’s ”Mukhtasar Ihya ‘Ulum al-Din”