I remember in 2012 asking an Ayatollah about this in Najaf. Here is what he told me.
Advice on how to get closer to Imam Mahdi (aj) –
The first thing he replied was that this is an easy thing to say, but in reality it is not an easy task to accomplish. He continued to say that we needed to pray to Allah and ask Him to open our container and expand our capacity, so that we can receive the knowledge pertaining to Imam Mahdi (pbuh). Being among those who are close to the Imam means having a very high level of knowledge and piety, so we must be prepared mentally and spiritually to understand, comprehend and accept this knowledge.
He proceeded to say that one of the ways that we can gain proximity to the Imam is to fulfill all of our obligations (wajibat) that Allah has asked from us. Next is to stay away from all of the things Allah has forbidden us from doing (muharramat). This reminds me of the first thing he told me when he said that it sounded easy but in reality, was not an easy task at all. Last of all he told me that to become close to the Imam we should be careful of how we treat others. We should always treat others well, with respect and give them their due rights. We should never be oppressors and mistreat people.
Also check out