Would farms/ranches in extremely rural areas be a safe place to be during SHTF? What are ways to be safe?

In a book I read, the author described what happened to rural communities when his country went though a long term collapse the city folk ran out into rural areas of the country and began raiding and doing harm to rural folk.

He said it was relatively safer to survive the collapse in the city than the rural areas because everyone knew rural people have livestock, natural water sources, crops, etc.

That is scary to me as a small homesteader on the outskirts of my city. I’m just worried if a long term collapse happens I would be a target.

How could one be safe if desperate people came to loot or take advantage of rural communities?