Mr. Mattis, who gained a reputation for bluntness during his years as a Marine Corps general, has appeared behind the lectern in the Pentagon briefing room only twice since he became defense secretary, the better to stay out of political debates, aides say. Mr. Mattis’s first, and only, appearance on the Sunday news shows did not come until four months into his term.

Mr. Mattis, his friends and colleagues say, is driven by several considerations, including his belief that the military’s political neutrality can help hold together a deeply divided nation — a point that Mr. Mattis hammered home in a commencement address last month at West Point in which he made one reference to the commander in chief and none to Congress.

Instead, he pointed to ancient Athens in hailing apolitical “defenders who look past the hot political rhetoric of our day” to protect “our experiment in self-governance.” The speech by Mr. Mattis, who is registered to vote in Washington State, which does not require political affiliations to be disclosed, stood in contrast to Vice President Mike Pence’s address at the United States Naval Academy commencement in which he referred to Mr. Trump a dozen times, calling him the “best friend the armed forces of the United States will ever have.”

Mr. Mattis’s low profile is part of his strategy for exerting influence from within, at one-on-one meetings with Mr. Trump or the dinners he has with the president and General Joseph F. Dunford Jr., the chairman of the Joint Chiefs of Staff. He was also at the White House last week while the president watched part of the highly anticipated congressional testimony by James B. Comey, the former F.B.I. director.

Mr. Mattis is trying to ensure he keeps his line to the president open so Mr. Trump can quickly be briefed on the issues that Mr. Mattis cares about the most. When the Syrian government launched a chemical weapons attack in April, Mr. Mattis rapidly presented his boss with possible responses; within 63 hours, a hail of missiles were fired on a Syrian airfield, the option Mr. Trump had chosen.