Teaching your dog to attack on command is not a job for amateurs, and your homeowner's policy probably wouldn't appreciate you having such a dog on hand, either. Fortunately, if you have a dog that barks when you want him to, either on your command or when someone comes to the door, you can deter many questionable situations. If someone is looking to break into a home, they will likely pass by the one where they can hear a barking dog.
Choose the word you want your dog to respond to. You can use something simple, like "speak," but stay consistent.
Set your dog up into a situation where he will get frustrated, as this is a pretty easy way to encourage your dog to bark. One way to do this is to tie your dog to a chair leg, then step around the corner and call your dog. When he can't come when called, he will likely yip in frustration. Rush back into the room, praising him, saying "good speak" (or whatever your verbal command is).
Repeat the process a few times, then take a break. Keep the training sessions short and high energy.
Try giving the command to speak first, before your dog barks. Once you have praised him for barking a few times, he will start to figure out what you want him to do. Even a short yap is worth a reward, his barking will become more confident once he is sure he understands what you want him to do.
Try him out with help from a friend. Arrange for them to meet you while you are walking, and give him the speak command. If your training is on track, he should bark.
Teach your dog to bark when someone comes to the door. Once he speaks on command, teach him to speak when the doorbell rings or someone knocks. This is a simple process as long as you have some help. Have someone outside ring the bell or knock. As you walk to the door, give your dog the speak command. When he barks, open the door and have your helper praise him. It won't take many repetitions for your dog to bark automatically when someone knocks on the door or rings the bell.