Redirect his attention: When you see your dog start to hump someone, immediately redirect his attention to a toy or treat. This helps him learn that humping is not appropriate.
Remove him from the situation: If humping continues, remove the dog and place him in a time-out. This shows that humping is unacceptable and helps him calm down.
Squirting water at him: Squirting water may deter humping, but use it only as a last resort and only if other methods fail. Avoid spraying the face, as it can harm the eyes. Instead, aim for the stomach or hindquarters.
Neuter your dog: If your dog is not neutered, the procedure may reduce humping by lowering testosterone levels.
Consult a trainer: If you struggle to stop the behavior, a professional dog trainer can create a plan tailored to your dog's needs.