SAN DIEGO — As the head of a homeless shelter in San Diego, Bob McElroy knows firsthand how epidemics can turn deadly for people living on the streets. Three years ago an outbreak of hepatitis A, an otherwise preventable and treatable disease, killed 20 people in San Diego County alone, most of them homeless.

Now as the coronavirus spreads across the country, Mr. McElroy is faced with a new threat, one that he can only hope to ward off with a stockpile of hand sanitizer. Under a single tent in downtown San Diego, his shelter sleeps more than 300 people, a majority of them over 50 years old, a warehouse of human beings arrayed like cadets in military barracks. Numbered bunk beds are spaced just two feet apart.

“We’re just saying our prayers,” Mr. McElroy said. “If it gets in here it would be a disaster.”