Bacteria have been shown to produce chemical signals that can alter neural activity and behaviour; however, the mechanisms involved are unclear. Here, the authors show that the ingestion of the gut-colonizing bacterial species Providencia by Caenorhabditis elegans reduces worms’ aversive responses to the usually repellent alcohol octanol and biases their feeding choices to make them more likely to select Providencia. The authors find that the bacteria exert this effect through the production of tyramine, which — following its conversion to octopamine — activates receptors on ASH sensory neurons to modulate the worms’ aversive responses and food selection.