As for longevity, that is from Allah alone; the human being has no say in it, for life spans are in Allah’s hand. Righteous action, however, is something a person can improve, for Allah has granted him intellect, revealed the scriptures, sent the messengers, clarified the straight path, and established the proof. Every individual, therefore, is able to perform good deeds. Indeed, when a person does a righteous act, the Prophet ﷺ informed us that certain good works are themselves a cause of longer life—among them keeping family ties. The Prophet ﷺ said, “Whoever would like his provision to be expanded and his lifespan to be extended, let him maintain his ties of kinship.” Maintaining those ties is thus one of the causes of longevity. Since the best of people are those whose lives are long and whose deeds are good, one should constantly ask Allah to grant him a long life coupled with righteous action, so that he may be counted among the best of people.
This also shows that mere longevity is not good for a person unless his deeds are righteous, for at times a long life can be harmful and detrimental. Allah says, “And let not those who disbelieve think that We grant them respite for their own good. We only give them respite so that they may increase in sin, and for them is a humiliating punishment” (Āl ʿImrān 3:178). Thus Allah affords those disbelievers wealth, health, long life, children, and spouses—not for their benefit but, Allah forbid, for their ruin, because through it they only multiply their sin.