How to have Ikhlass
First: having pure Tawheed of Allah (mighty and majestic). Allah says: 2- …(being) sincere to Him in religion. 3- Unquestionably, for Allah is the pure religion (Az-Zumar: 2-3).
Allah the Exalted also says: "They were not commanded except to worship Allah, (being) sincere to Him in religion" (Al-Baiyinah: 5). Every outward action which contradicts one’s inward thoughts and deeds is false
Second: being a true follower of the Prophet (peace be upon him), obeying him in his commands, abstaining from his prohibitions and believing in whatever he conveyed. Allah (mighty and majestic is He), says: "O you who have believed, obey Allah and obey the Messenger, and those in authority among you. If you disagree over anything, refer it to Allah and the Messenger, if you should believe in Allah and the Last Day. That is the best (way) and best in result" (An-Nisâ": 59).
Third: if you want to have Ikhlass, be careful to continue to do good deeds properly, and always remember the seven kinds of people who will be in Allah"s shade on that Day when there will not be any shade but His, one being described below: "A man who givese charity in secret…" (Narrated by al-Bukhari).
Also remember that: "The reward of deeds depends upon the intentions…" (Narrated by al-Bukhari).
Fourth: always praise Allah from the bottom of your heart, and stop looking at what people have. Your bond should be with Allah, your Creator (mighty and majestic is He), for a person who has Ikhlass does not look forward to having a worldly gain or a spouse to marry, but rather he looks forward to achieving Allah"s Mercy.
Fifth: you have to throw your self at the doorstep of Your Lord, demonstrating submissiveness and subordination, imploring Him to provide you with Ikhlass, to purify you from hypocrisy, and to forgive all of your sins and wrongdoings. To have Ikhlass is to abstain from seeking a person to see your good deeds except Allah, and to expect rewards from only Him.
Sixth: to avoid and be aware of hypocrisy and showing-off. If a slave of Allah begins to know the path to hypocrisy and lets it enter the soul, he will completely distance himself from being able to have Ikhlass. An example of this is when one describes himself, or accepts that people name him as a Waley (a pious man who is supported by Allah), or boasts about his good deeds and acts of worship. Allah (mighty and majestic is He) says: 15- Whoever desires the life of this world and its adornments - We fully repay them for their deeds therein, and they therein will not be deprived. 16- Those are the ones for whom there is not in the Hereafter but the Fire; and lost is what they did therein, and worthless is what they used to do (Hûd: 15-16).
Hypocrisy is an act of minor shirk and it suffices that one of its disastrous results is that Allah does not accept a person"s deeds, even if it appears to be good, but He throws it back at its doer.
Seventh: seeking companionship of those who are sincere. The Prophet (peace be upon him) said: "A man follows the religion of his friend; so each one should consider whom he makes his friend" (Narrated by at-Tirmidhi). Ikhlass cannot exist in a person’s heart together with the love of praise and tributes from others, just as fire cannot exist with water.
Eighth: Conealing oneself when worshipping Allah, and performing acts of worship in secret. Allah the Exalted says: "If you disclose your charitable expenditures, they are good; but if you conceal them and give them to the poor, it is better for you" (Al-Baqarah: 271).
Ninth: seriously and continuously searching one’s soul at all times. Allah (mighty and majestic is He) says: " Those who strive for Us - We shall surely guide them to Our ways" (Al-"Ankabût: 69).
Contemplate over Allah"s Words which He uses here: "…for Us " !!
Tenth: continuously supplicating Allah and seeking His Face and pleasure. A slave in need of Allah will obtain His mercy and be granted his needs if he continuously knocks on Allah’s door.