He did it the same way as Mao and Stalin did. He purged his enemies and built up a cult of personality. Then, in the late 60's/early 70's he started the same process for his son (Kim Jong-il) who, in turn (belatedly), started the same process for HIS son (Kim Jong-eun).
The long version - he was placed in power by the Soviets at the end of World War II. Kim Il-sung was a cunning guy - he and his fellow anti-Japanese fighters were good lap dogs of the Soviets. In 1949, the communists in China had won the civil war and Mao was in power. In 1950, with Stalin and Mao's backing, Kim started the Korean War. The war didn't help Kim directly (since he lost), but he was able to create a bogeyman in the US forces, which he, the Great Leader, had stood up to and prevented from conquering the North. In 1957, there was an attempt to overthrow Kim by an opposing faction of North Korean communists. They were purged - executed, forced into exile, or sent to prison camps. From that point on, there would never be any real, credible attempt to unseat Kim.
It was at this point that history began to be rewritten. Kim Il-sung's anti-Japanese exploits began to take on a larger life. As far as is actually known, he WAS an anti-Japanese guerrilla fighter and the Japanese DID post a reward for his capture, but he was about as important as Hitler was during WWI - just another face in the crowd, really. But his biographers began beefing up his resume with the end result being that he single-handedly defeated all of Japan and saved the Korean people. Statues began being erected, people wore pins of his likeness, his photo was in everyone's home. Every new textbook included new feats, new achievements that the Great Leader had accomplished.
Couple this absurdity with a strong police state and the loyalty of the military and other upper apparatchiks (paid for by the state, controlled by Kim) and you have the foundation for the Kim family. When Kim Jong-il came onto the scene, the same thing happened - new and amazing things that the Dear Leader had accomplished, statues to him were built, his likeness went next to his father's, etc. Kim Jong-il had a solid 20 years of being built up before Kim Il-sung died in 1994. Kim Jong-il attempted this with HIS son, Kim Jong-eun, but he died much sooner than he had anticipated.
A solid book on the Kim Family is Under the Loving Care of the Fatherly Leader: North Korea and the Kim Dynasty by Bradley K. Martin. It's very in depth and it shows the extreme lengths that they went to to establish the cult of personality.