Background: Stroke and depression are the two most common causes of disability worldwide. Growing evidence suggests a bi-directional relationship between stroke and depression, whereas the molecular mechanisms underlying stroke and depression are not well understood. The objectives of this study were to identify hub genes and biological pathways related to the pathogenesis of ischemic stroke (IS) and major depressive disorder (MDD) and to evaluate the infiltration of immune cells in both disorders.Methods: Participants from the United States National Health and Nutritional Examination Survey (NHANES) 2005–2018 were included to evaluate the association between stroke and MDD. Two differentially expressed genes (DEGs) sets extracted from GSE98793 and GSE16561 datasets were intersected to generate common DEGs, which were further screened out in cytoHubba to identify hub genes. GO, KEGG, Metascape, GeneMANIA, NetworkAnalyst, and DGIdb were used for functional enrichment, pathway analysis, regulatory network analysis, and candidate drugs analysis. ssGSEA algorithm was used to analyze the immune infiltration.Results: Among the 29706 participants from NHANES 2005–2018, stroke was significantly associated with MDD (OR = 2.79,95% CI:2.26–3.43, p < 0.0001). A total of 41 common upregulated genes and eight common downregulated genes were finally identified between IS and MDD. Enrichment analysis revealed that the shared genes were mainly involved in immune response and immune-related pathways. A protein-protein interaction (PPI) was constructed, from which ten (CD163, AEG1, IRAK3, S100A12, HP, PGLYRP1, CEACAM8, MPO, LCN2, and DEFA4) were screened. In addition, gene-miRNAs, transcription factor-gene interactions, and protein-drug interactions coregulatory networks with hub genes were also identified. Finally, we observed that the innate immunity was activated while acquired immunity was suppressed in both disorders.Conclusion: We successfully identified the ten hub shared genes linking the IS and MDD and constructed the regulatory networks for them that could serve as novel targeted therapy for the comorbidities.