It really depends on the setting, and to some extent the edition and system.
In a D&D 3.5 game I had the party journey to a valley that was ruled by a Necromancer. The people who lived there were afraid of him, but had to admit that he kept them safe. Wee Jas is the deity of death and magic in that edition, and is Lawful Neutral. Technically a follower or Cleric could be Lawful Good. Mine wasn't, he matched the alignment of his deity, Lawful Neutral.
Her domains are Death, Law and Magic, and use of the undead is just fine with her.
It kind of drove the party Paladin nuts that the Necromancer lord didn't register as Evil, and that he didn't actually have any grounds to overthrow the "lawful ruler" of the region. In fact he saw some acts of generosity and mercy on the part of the Necromancer, when the situation allowed for it. Still, it twerked the Paladin more than a little to have to deal with the man,
Part of the key was the setting and situation. The valley was isolated, with tribes of savage humanoids and giant types (Ogres to be specific) well established around them. The Necromancer defended the valley from them, usually by animating the corpses of those same humanoids and giant-types.
So, while the people were afraid that some of the "guardians" might kill and eat them if left unsuervised, they
knew that the savage tribes around the valley would definitely kill and eat them if they weren't held at bay.
The Necromancer considered undead as useful, if distasteful tools, and nothing more. He knew his limits, how many he could directly control. When the party first encountered some of the valley's human guards, those guards were riding down a group of Wights. the Necromance had direct control over at least one Wight, who in turn exercised control over those it had created, whe then controlled their creations and so on, But if one of the command ranks gets killed, all who were in the command tree below that had to be eliminated. They were a free range catastrophe waiting to occur.
The party, seeing what appeared to be mounted knights riding down peasants, went to intervene. Then the Wights turned on them, and up close they realized what they'd done, what they'd been defending.
Story wise it was a wonderful moment, generating confusion and some conflict without actually harming the party significantly injuring anyone.
The valley had limited resources, and the ability to assign a work crew of undead monster types to do simple, near mindless tasks like building and maintaining roads and occasionally plowing fields etc. helped keep the place safe, keep things together and keep people fed.
In that situation he understood that maintaining order was necessary for his people to survive, while the moral considerations of good and evil were almost incidental. Get too obsessed with such distractions meant people died. You used what tools you had, and his tools were the walking dead.
Now, to generalize this across systems and revisions, let's look at the key elements that might work for a PC.
1) You don't use the corpses of any race that lives in the area as "people" It's not just a matter of them not seeing uncle Joe walking around as a rotting monstrosity, it's using dead "enemies" of the town.
2) You don't have to be Evil, at least not in any way that can be sensed through magical detection.
3) Reveal yourself as a Necromancer only when there's great need for the town or region. Now the enemy of my enemy can still be a son-of-a-birchtree, but he isn't my enemy, particularly when he's busy saving me and my family.
Oh, and if you want to cover expenses and maybe earn some coin, make sure you corner the local market on torches and pitchforks,
