Gut microbiota have been shown to influence the social behaviors of their hosts, while variations in host genetics can affect the composition of the microbiome. Nonetheless, the degree to which genetic variations in microbial populations impact host behavior, as well as any potential transgenerational effects, remains inadequately understood. Utilizing C. elegans as a model organism, we identified 77 strains of E. coli from a total of 3,983 mutants that significantly enhanced aggregation behavior through various neurobehavioral pathways. This discovery underscores a collaborative regulatory mechanism between microbial genetics and host behavior. Notably, we observed that some mutant bacteria might affect social behavior via the mitochondrial pathway. Additionally, the modulation of social behavior has been identified as a heritable trait in offspring. Our results provide a novel perspective on the regulatory role of microbial genetic variation in host behavior, which may have significant implications for human studies and the development of genetically engineered probiotics aimed at enhancing well-being across generations.