SpaceX is only a couple of months away from its first attempt at launching astronauts and the company has brought in one of the foremost experts in human spaceflight to help it do so successfully.

William Gerstenmaier, the former leader of NASA's human spaceflight program, has now begun working at SpaceX headquarters in Hawthorne, California, people familiar with his hiring told CNBC. In his new role Gerstenmaier is reporting to SpaceX vice president of mission assurance Hans Koenigsmann, those people said, as the company prepares to begin launching astronauts.

A SpaceX spokesperson confirmed that Gerstenmaier is a consultant for the company's reliability engineering team.

Previously Gerstenmaier served as the NASA Associate Administrator for Human Exploration and Operations for nearly 14 years. In total he had a four decade career with NASA, working on programs ranging from the Space Shuttle to the International Space Station. Gerstenmaier is widely considered one of the world's top specialists in flying humans in space, frequently testifying before Congress on the subject.

His move to private side of the space industry comes after Gerstenmaier was demoted at NASA in July, in a surprise shake-up of top leadership. A memo from NASA administrator Jim Bridenstine announcing Gerstenmaier's reassignment did not explain the cause of the change, but simply thanked him for providing "the strategic vision for some of NASA's most important efforts."

His hiring at SpaceX comes at a critical time for Elon Musk's space company, which is planning its first launch of NASA astronauts between April and June of this year. Called "Demo-2," the mission would fly two astronauts in a SpaceX Crew Dragon capsule to the International Space Station. It would be the first time since the end of the Space Shuttle program in 2011 that the U.S. has flown its own astronauts to space.