David Shea, a retired typographer, thought that he was renting out his large enclosed terrace to a visitor from Miami who was looking for a cheap place to stay for a few days in Manhattan. The man had contacted him through Roomorama.com, one of several websites that connect travelers with private hosts.

When the man arrived, Mr. Shea smuggled in his luggage in a laundry cart so as not to attract attention from his neighbors or the co-op board of his affordable housing development. He told the man to say he was a friend if anyone asked. But once upstairs, the man suddenly decided to leave, saying that the shabbily decorated terrace that September night was too hot.

The next month, Mr. Shea received notice that he was facing eviction proceedings. The man from Miami, it turned out, was actually a private investigator sent in by his co-op board. Mr. Shea, 78, is now fighting to remain in his apartment, arguing that eviction is an excessive punishment.

“If I get kicked out of here, I might end up homeless, and I’ve been homeless before,” he said last week in the fading afternoon light on his terrace, a sweeping view of Midtown behind him. “Or I’ll have to move to some small town where I know nobody. And believe me, once you hit my age, it’s very, very difficult to make new friends.”