Answered by Sayyidi Habib Umar bin Hafiz (may Allah protect him and benefit us by him)
Does a person benefit from keeping the company of the pious scholars if he or she does not perform many good actions?
This is what the Messenger of Allah ﷺ was asked, as is narrated in Sahih al-Bukhari. One of the Companions asked: “What is the fate of someone who loves a group of people but has not attained their level of piety?”
He said very simply: “A person is with the one he loves.”
He also said ﷺ, as has been narrated in the authentic hadith: “A good companion is like a seller of musk whereas a bad companion is like a blacksmith. The musk seller will give you some of his wares, you may buy some perfume from him or at the very least you will smell on him a pleasant odour..”
One of the pious said:
The guides of mankind – good tidings to a slave who sees them
And keeps their company even once in his life
They are the scholars, the knowers, in whose company
A person attains the highest felicity
If someone spends time in their presence while loving them and desiring to imitate and follow them, he they will attain the highest of stations. If someone does so without desiring to imitate them he will nonetheless attain blessings as long as he does not go against their methodology by persisting in violating the Sacred Law. If someone spends time in their presence seeking status and rank amongst people without attempting to leave acts of disobedience to Allah, this will be a proof against him.
In summary, if a person’s intention is sound and he is not content to allow himself to violate the Sacred Law then keeping the company of the pious is of great benefit to him even if he does not perform many good actions. If a person’s intention is not sound, however, and he keeps their company for some contemptible worldly benefit or persistently violates the Sacred Law, then doing so will be of no benefit and will be a proof against him and we take refuge in Allah from that.