Background: Aflatoxin, which is highly carcinogenic and toxic, can seriously threaten the quality and safety of agricultural products, is mainly produced by Aspergillus flavus, which mainly exists in the soil of farmland. However, the correlation between aflatoxin, the microflora and environmental factors that survive in the roots of the plant is currently unknown. In this study, we used peanut-associated microbial populations as a model to address these issues.Results: We illustrated here that peanut pods significantly enriched with fungi and bacteria phyla. In the aflatoxin low pollution area, fungal and bacterial were more abundant than the high-pollution area, and the proportion of bacterial populations negatively correlated with aflatoxin was higher. However, some functions related to microbial-microbial and plant-microbial interactions were significantly enriched in areas with low levels of aflatoxin. Besides, we found that pH, Fe, Zn, P of the soil and temperature and humidity were the main factors that caused the differential composition and functional characteristics of microorganism. They can significantly affect the relationship between microbial flora and Aspergillus flavus and positively regulate aflatoxin production and microbial metabolism pathways, while OM, K, and other elements negatively regulated aflatoxin production and microbial metabolism pathways.Conclusions: The abundance of Aspergillus flavus and aflatoxin are significantly regulated by the population structure and function of microbiota, and this regulation is primarily affected by soil physical and chemical properties. Our results provide novel insights for understanding the contributions of the community enrichment process of the peanut pod-associated microbiome to the peanut hosts.