KABUL, Afghanistan — U.S. Defense Secretary Jim Mattis arrived in Kabul on Friday to meet the new commander of NATO troops in Afghanistan and discuss progress on talks with the Taliban, despite deteriorating security and turmoil within the Afghan government.

The United States is a year into its latest attempt to step up pressure on the Taliban by increasing air strikes and sending thousands more troops to train and advise Afghan forces, but the effort has yet to make Afghanistan more secure and stable. The 17-year-old war is America's longest conflict.

Mattis is accompanied by Chairman of the Joint Chiefs of Staff Marine General Joseph Dunford. The surprise visit is Mattis' fourth time in the country since becoming defense secretary, and it's part of a larger trip including stops in San Diego and India.

U.S. Army General Scott Miller assumed command of NATO forces in Afghanistan on Sunday, arriving as Washington faces growing questions over its strategy to force the Taliban into talks to end the grinding conflict.

Speaking with reporters this week, Mattis said he was hopeful about peace talks with the Taliban.

"Right now, we have more indications that reconciliation is no longer just a shimmer out there, no longer just a mirage," Mattis said.

"It now has some framework, there's some open lines of communication," Mattis added.

Over the summer, a top U.S. State Department official met Taliban officials in Qatar to try to lay the ground work for broader peace talks.

The U.S. government has pointed toward the Taliban accepting a temporary truce in June, as a sign of why the talks should be viewed with hope.

"The most important work that has to be done is beginning the political process and reconciliation," Dunford told reporters travelling with him.

"What we are trying to do in the military dimension is convince the Taliban that they cannot win on the battlefield and that they must engage in a peace process."

Privately, however U.S. officials and experts are more cautious.

A U.S. official, speaking on the condition of anonymity, said it was unclear how much influence the Taliban officials in Doha, Qatar, had over the group's leadership.

"I think that both the U.S. and Afghanistan have perhaps exaggerated the good news in Afghanistan," Michael Kugelman, with the Wilson Center think-tank in Washington.

Two insurgent commanders have told Reuters that the Taliban rejected a second ceasefire offered this month by Afghan President Ashraf Ghani.

Mattis' visit to Afghanistan comes amid recent attacks.

A U.S. service member was killed and another wounded Monday in "an apparent insider attack" in eastern Afghanistan, according to a statement from the Resolute Support, the NATO-led coalition in Afghanistan.

On Wednesday, 20 people were killed in twin bomb attacks in Kabul. ISIS claimed responsibility for the attack.

There are approximately 14,000 Americans in Afghanistan.

—CNBC's Amanda Macias contributed to this report.