New York City, which has the country’s largest homeless population, has identified coronavirus cases in dozens of shelters. In Silicon Valley, a homeless person living in an encampment died of the disease. At least a dozen homeless people have tested positive for the virus in Los Angeles County, according to authorities.

San Francisco has deployed a dual strategy in trying to protect its homeless population, spacing out beds in homeless shelters and lifting its ban on tent encampments. Many streets, largely empty of other residents, are now lined with camping tents that city workers make sure are kept at least six feet apart.

“We are no longer trying to break up encampments, whether it’s one tent or 15 tents,” said Jeff Kositsky, a city official charged with managing the coronavirus response for the roughly 5,000 people in San Francisco who sleep on the streets.

“We are trying to stay focused on letting people shelter in place.”

Experts say cities face a dilemma in addressing the homelessness crisis during the pandemic. Bringing people indoors offers access to showers and bathrooms but might also make the virus more transmissible.

“The shelters present a greater risk of transmission because you have people interacting and sleeping in close quarters,” said Linsey Marr, an expert in airborne disease transmission at Virginia Tech. “You have much greater density of people.”

Mr. Kositsky said that in addition to homeless people, hundreds of city employees charged with looking after them were also vulnerable to the virus.

“I’m out with the outreach workers and none of us have protective gear,” he said.