President Trump second-guessed generals on the campaign trail, but in office he has relied heavily on their counsel, with the ascension of retired Gen. John Kelly to White House chief of staff serving as the latest example.

"If anybody can create discipline out of the chaos, it is someone like the general," said David Cohen, a professor of political science at the University of Akron who has written about the evolution of the chief of staff role. "He's used to the chain of command, a military org chart. But only if he has truly been empowered to regulate access to the president, including the president's children."

Trump told reporters in January that he would let one retired general, Defense Secretary James Mattis, "override" him on torture. He later gave Mattis authority to set troop levels in Afghanistan. A source close to Trump praised the president for choosing "arguably the greatest general of his generation" to run the Defense Department.

Another general, national security adviser H.R. McMaster, has been credited — or blamed, depending on your perspective — for Trump's taking a more interventionist stance in Syria than during the campaign.

Yet another general, McMaster's predecessor as national security adviser, Michael Flynn, has been at the center of the Russia investigation that has bedeviled the president the whole time he has been in office. A lot of the scrutiny around Trump personally regarding Russia stems from his reported insistence that investigators let Flynn go, the main contention made by fired FBI Director James Comey.

Some Democrats have criticized Trump for undermining civilian control of the military by having so many current and recently retired generals in his administration. Rep. Barbara Lee, D-Calif., tweeted that Trump's Kelly appointment constituted "militarizing the White House."

Kelly is now the general at the helm of the White House staff. Trump gained confidence in him during his service as secretary of Homeland Security, a position from which he often had to defend the president's controversial positions on immigration and national security.

"The president's selection of General Kelly, among other esteemed Marine generals, underscores the fact that President Trump is a fighter, values fighters, and respects the hell out of those who've put their love of country above all else," said Erin Montgomery, communications director for America First Action, a pro-Trump super PAC. "Who understands the true meaning of strength in leadership better than someone who has spent a lifetime in our nation's uniform?"

One of Kelly's first acts after replacing former chief of staff Reince Priebus was to oust short-lived communications director Anthony Scaramucci, a flashy and eloquent but undisciplined spokesman for the president whose vulgar tirades against fellow White House staffers wound up appearing in the New Yorker.

"Scaramucci broke two rules," said a Republican strategist requesting anonymity to speak candidly. "In this White House, you don't upstage the boss. And now you can't be a loose cannon around General Kelly."

"General Kelly has the full authority to operate within the White House, and all staff will report to him," press secretary Sarah Huckabee Sanders assured reporters at Monday's daily briefing.

Trump has a reputation for being a demanding boss. He has publicly chastised Attorney General Jeff Sessions, one of his earliest influential supporters who gave up a safe Senate seat to serve in the cabinet. Since Priebus departed and Sean Spicer announced his resignation as White House press secretary, there have been reports that these high-level staffers faced intense criticism and were occasionally pressed into performing mundane tasks.

But Trump has been more deferential to the generals in his midst. "I see my generals," he boasted at a luncheon early in his administration. "These are central casting. If I'm doing a movie, I'd pick you general, General Mattis."

Sen. Lindsey Graham, R-S.C., recently told a crowd in Washington, D.C., that this deference extends throughout the armed forces. "[T]he thing I like most … is he gets his limitations when it comes to the military," Graham said.

Graham recounted a story from Mattis about a request to send troops into a Syrian village. Trump asked Mattis who wanted to go into the village. "A major, first in his class at West Point," Mattis replied, according to Graham.

"Why do you think I know more about that than he does?" Trump shot back before hanging up the telephone.

"There's an advantage [Kelly] has as a general," said Cohen. "There's a certain reverence Trump has for the military, at least."

But it doesn't extend indefinitely. Trump recently blindsided civilian and military leaders by suddenly announcing a transgender ban on Twitter, despite citing "consultation with my Generals and military experts" as justification for the move.

During the campaign, Trump said that under former President Obama and Hillary Clinton "I think the generals have been reduced to rubble" and suggested he might seek military advice from "different generals." The comments were widely interpreted as a threat to fire generals.

Trump also did not let Sen. John McCain's, R-Ariz., military service get in the way of his criticizing him harshly when the two men clashed in 2015. Trump said of the Vietnam POW he preferred heroes who weren't captured.

That's why some think Kelly is arguably taking on his toughest assignment yet.

"Is the president himself willing to help the chief of staff impose discipline on him?" Cohen asked. "He's an impulsive 71-year-old man who is used to running his businesses, his TV shows, the way he wants to."

"He needs to shut down the competing power centers in the White House, make all subordinates understand they are on the same team," Cohen added. "Stop the constant leaking of the White House's dirty laundry."

All tall tasks that have wound up being a general's mission.