Through practicing samatha and vipassana meditation. After abandoning the five hindrances and after mastering the Jhanas a practitioner turns their attention to and attains Insight Knowledge, Supranormal Powers, Clairaudience, Mind Reading, Recollection of Past Lives, The Passing Away & Re-appearance of Beings, The Ending of Mental Fermentations and Conversations with the Gods.
From the Maha-Assapura Sutta:
With his mind thus concentrated, purified, and bright, unblemished, free from defects, pliant, malleable, steady, and attained to imperturbability, he directs and inclines it to knowledge of the recollection of past lives. He recollects his manifold past lives, i.e., one birth, two births, three births, four, five, ten, twenty, thirty, forty, fifty, one hundred, one thousand, one hundred thousand, many aeons of cosmic contraction, many aeons of cosmic expansion, many aeons of cosmic contraction and expansion...
With his mind thus concentrated, purified, and bright, unblemished, free from defects, pliant, malleable, steady, and attained to imperturbability, he directs and inclines it to knowledge of the passing away and re-appearance of beings. He sees — by means of the divine eye, purified and surpassing the human — beings passing away and re-appearing, and he discerns how they are inferior and superior, beautiful and ugly, fortunate and unfortunate in accordance with their kamma...
From Kevatta (Kevaddha) Sutta: To Kevatta:
With his mind thus concentrated, purified, and bright, unblemished, free from defects, pliant, malleable, steady, and attained to imperturbability, he directs and inclines it to the divine ear-element. He hears — by means of the divine ear-element, purified and surpassing the human — both kinds of sounds: divine and human, whether near or far.
With his mind thus concentrated, purified, and bright, unblemished, free from defects, pliant, malleable, steady, and attained to imperturbability, he directs and inclines it to the modes of supranormal powers. He wields manifold supranormal powers. Having been one he becomes many; having been many he becomes one. He appears. He vanishes. He goes unimpeded through walls, ramparts, and mountains as if through space. He dives in and out of the earth as if it were water. He walks on water without sinking as if it were dry land.
With his mind thus concentrated, purified, and bright, unblemished, free from defects, pliant, malleable, steady, and attained to imperturbability, he directs and inclines it to knowledge of the awareness of other beings. He knows the awareness of other beings, other individuals, having encompassed it with his own awareness. He discerns a mind with passion as a mind with passion, and a mind without passion as a mind without passion. He discerns a mind with aversion as a mind with aversion, and a mind without aversion as a mind without aversion. He discerns a mind with delusion as a mind with delusion, and a mind without delusion as a mind without delusion. He discerns a restricted mind as a restricted mind, and a scattered mind as a scattered mind.