Coincidentally, it's the same way you teach people to do anything else.
As a teacher, here are the two things you need to do:
First, identify the gaps in their knowledge. Second, fill in those gaps.
Easier said than done.
You have to know your students fairly intimately. You have to find out how much they know, and perhaps more useful, how much they don't, before you can attempt to start. You'll have to know their goals, so you can at least point them the right way, and you'll have to be able to steer them away, when you know that the direction they want to go will end in disaster.
At first, it will seem daunting. The 'gap' in knowledge will be more like a gaping maw. It will be that way for a long time, and the first few nuggets of knowledge will be the hardest to convey. You'll struggle with terminology, using imperfect analogies to relate completely alien ideas. You won't even be speaking the same language at first.
Once they've mastered some basics, it gets a little better in some ways. Your student will have a platform from which they can see their goal and they can start walking, filling in the gaps for themselves as they go. Your job will change. Instead of feeding them knowledge, you'll be showing them where to find it, removing roadblocks, placing signposts, unveiling interesting detours and shortcut, keeping them motivated. At this point, you're not teaching as much as you're guiding, but for every step they take, you'll already have taken 30, making sure the path was right in the first place. It's a different path and a different goal for every student.
Imagine teaching twenty people. It's exhausting.
How can anyone do this reliably? I don't know how he does it, but you can see it in action here. As much as I dislike Zed's internet persona, it's clear to me that he's an amazing teacher. He cares about his students and answers every single one of their questions at the level they need, pointing them in the right direction. On top of being a good programmer, he's a good teacher and wants to share what he knows. That is how you teach people how to program.