Microbes are ubiquitous on Earth, forming microbiomes that sustain macroscopic life and biogeochemical cycles. Microbial dispersion, driven by natural processes and human activities, interconnects microbiomes across habitats, yet most comparative studies focused on specific ecosystems. To study planetary microbiome structure, function, and inter-habitat interactions, we systematically integrated 85,604 public metagenomes spanning diverse habitats worldwide. Using species-based unsupervised clustering and parameter modeling, we delineated 40 habitat clusters and quantified their ecological similarity. Our framework identified key drivers shaping microbiome structure, such as ocean temperature and host lifestyle. Regardless of biogeography, microbiomes were structured primarily by host-associated or environmental conditions, also reflected in genomic and functional traits inferred from 2,065,975 genomes. Generalists emerged as vehicles thriving and facilitating gene flow across ecologically disparate habitat types, illustrated by generalist-mediated horizontal transfer of an antibiotic resistance island across human gut and wastewater, further dispersing to other habitats, exemplifying human impact on the planetary microbiome.