The Prophet (Allah’s blessings and peace be upon him) said:
“And the destroyers are: desires which are followed; stinginess which is obeyed; and a man being pleased with himself, and this. (last trait) is the worse of them (of the things which spiritually wrought destruction to one).”
Ujub is to attribute one’s excellence to oneself while being oblivious of the possibility of such excellences being snatched away by Allah. Ujub is a concealed and subtle trick of the nafs which always desires to occupy a distinguished rank (above others). The nafs obtains pleasure in this desire (of ujub). Allah detests one who considers himself to he distinguished, laudable and the receptacle of excellences.
Delight over the bounties granted by Allah is not ujub. Such true delight is not unrestricted and does not produce vanity since the fear of the elimination of the bounties is ever present in the heart. One realizes that the excellence or bounty which one has gained is purely a gift from Allah Who has awarded it because of some act or knowledge (which is also the favor of Allah), and one further realizes that Allah has the full power of snatching away the bounty at any time He desires. This experience of delight is therefore not ujub.
On the other hand, a person suffering from the ailment of ujub becomes neglectful and fails to recognize that the bounty in his possession is in fact a gift from Allah. One afflicted with ujub considers himself to be entitled to the bounties.
THE REMEDY
Always regard excellences and virtues which one possesses to be the bestowal of Allah. Contemplate on the power of Allah and fear the possibility of the gifts being snatched away. Ponder about your faults, both internal and external so that the notion of perfection and holiness is annihilated.
Path to Perfection, Mawlana Masihullah Khan (Allah have mercy on him)