Let's set a scenario here. You are in your home sleeping comfortably on the couch and then suddenly a door opens. You run towards the door and see someone approaching your housemate. You have never in your life seen this person and have no idea why they are in your home.
They move closer towards your housemate, and your housemate doesn't react. Is their non-reaction social proof that this is a nice person they invited into the home or are they frozen in fear unable to move? If you take action and yell at or attack the stranger and are wrong then you will have made a terrible mistake but if this is an intruder here to cause harm and you do not act your housemate could wind up injured or worse. The options are to cause a scene and possibly harm an innocent stranger or not to cause a scene and possibly watch your housemate get brutally murder before your vary eyes. As you do not want your housemate to be brutally murdered and in this scenario a false positive of a recognized threat is a lot less harmful than a false negative you charge in and bite the stranger.
As it turns out in this scenario the stranger was a friend invited to the house and you were a dog. Now you are deemed a bad dog and a menace to society. Biting a human will go on your permanent record and if this mistake is made again there will be no choice but to have you put down. While a dog skipping over barking, growling, baring of teeth, and other methods of scaring off a perceived threat isn't uncommon it is one of the ways in which dogs are misunderstood and end up labeled bad dogs when they just need to be taught or retaught social interaction. Dogs and humans behave and interact differently, and while we may invite a stranger into our home the dog doesn't know this is someone we invited into our home and if they view it as enough of a threat an attack and bite is a better outcome to them than being wrong and assuming the stranger is a non-threat and everyone in the house winding up dead.
The behavioral issue I've described above is territorial aggression and all dogs have it to some degree (our Corgi would bark at noises he heard outside but if a human entered his home he'd show them where his leash was) but the ones that we think of as having it are the ones that skip the kinder ways of determining of if someone is a threat and go right into attack mode. The most common cause of territorial aggression and almost any undesirable behavior in dogs is caused by lack of proper socialization in the crucial early weeks of their life. Dogs learn most of what they learn between the ages of three weeks and twelve weeks old. It is in this early three month period that puppies should be introduced to strangers coming and going from the home, other dogs, cats, cars, and any other stimulus that you'd like them desensitized to. As it is better to adopt a dog from a shelter or rescue they may already have these issues and the most likely cause is improper socialization as a puppy.
Correcting and already learned behavior can be difficult but it is far from impossible. It is important to understand two things. There are no bad dogs. your dog may be displaying undesirable behavior but that behavior is learned and logical to them. Think about how many wars have been started over cultural misunderstandings. Your dog's undesirable behavior is simply a failure for you and him or her to understand each other's culture and it is on you to find a way to explain proper behavior to him or her. That can be don in several ways. If the only trigger for the aggression is the territory one solution could be to hire a professional in home pet care specialist and go through a series of introductions between them and your pet starting with an off-site introduction in a relaxed atmosphere free of any other dogs and people. You, your dog, and your newly hire partner in pet care. After this start having them come to your home. If the dog is used to their scent and lets them in with no issue excellent. You know now to find the end of your dog's territory and can start inviting guests over and having your dog meet them outside the boundaries of their territory which you can slowly shrink for each introduction.
If the dog is still aggressive back in their territory then this is also excellent. The introduction will be easier since it is a person they already know and not a stranger but it is good because the ultimate goal is to be able to have company without them getting attacked by your dog. This is where a step by step process comes in. When does your dog start displaying aggression and what is the first sign? Does your dog rise when they hear a car a block away or do they show no signs of possible aggression until they hear steps coming up your walk and then they charge the door barking? Look for the first sign of aggression and then get them through that. Have your in home pet care specialist go through this first trigger multiple times until there is no reaction and then give your dog a treat. Once they show no reaction without needing a treat move on to the next step someone would take to enter your home. Once the person is able to enter your home with no reaction from the dog make them and everyone that enters your home give your dog a treat but not just for them entering. Your dog should now have to earn the treat from the person entering your home. Have them sit or stay in a spot or lay down in their bed but have your guests give them a command and when the dog obeys it they will earn a treat.
Will this method work for all dogs? No. There are no absolutes in life and there can be underlying medical issues that cause territorial aggression but most of the time it is a lack of socialization and in those instances the behavior can be corrected but the first step to any behavioral modification in dogs is to understand there are no bad dogs.