SINGAPORE — The acting defense secretary, Patrick Shanahan, distanced himself on Friday from a Trump administration decision to try to hide a ship named after Senator John McCain during the president’s visit to a naval base in Japan this week.

Mr. Shanahan, who was in Singapore for a security conference, told reporters that he would not have moved the destroyer to keep it out of photos with Mr. Trump.

The White House military operations office told the Navy to block the ship from view, and it complied by at first placing a tarp over the name of Mr. McCain, a fierce critic of Mr. Trump who died last year, and then moving a barge near the vessel.

“I would not have moved the ship,” said Mr. Shanahan, who is facing a tough Senate confirmation battle. “I would not have given that direction.”