Bill Samuel, the director of government affairs for the A.F.L.-C.I.O., said the political breakdown of his 12.5 million members is bipartisan and mirrors that of any large cross-section of America. “He seems to see them as well-paid professionals working in downtown Washington, D.C.,” Mr. Samuel said. “But on average, politically, we’re like the rest of the country.” About 79 percent of federal employees work outside the Washington area, with Texas, Virginia, California and Maryland having the largest number of government workers.

But Mr. Trump has little sense of the life of a typical government employee, and views them negatively overall, according to former White House officials. One former official said Mr. Trump saw government workers as part of the bureaucracy, and some as part of the deep state.

A second former official said the idea of federal workers toiling without pay left Mr. Trump unmoved.

Hogan Gidley, a White House spokesman, disputed that notion.

“The president cares about the future of all American workers in the public and private sector that have been forgotten by phony politicians for decades, and he wants to ensure their safety and security, which is why he continues to fight for border security,” Mr. Gidley said.

Marc Short, the former White House director of legislative affairs, pointed out the vocal support Mr. Trump had received from some federal employees. “I think it’s fair to say he’s cherished the support he’s gotten from federal unions and the National Border Patrol Council,” he said. “And I never heard him harbor any ill will toward government workers.”

On Thursday afternoon, in a surprise appearance in the White House briefing room, Mr. Trump appeared with a group of Border Patrol and Immigration and Customs Enforcement agents, government workers who enthusiastically endorsed his fight for a wall.

But the impression Mr. Trump has left on union members who do not work directly on national security issues appears to be much different.