Background & aimsThe effects of SARS-CoV-2 infection can be more complex and severe in patients with hepatocellular carcinoma (HCC) as compared to other cancers. This is due to several factors, including pre-existing conditions such as viral hepatitis and cirrhosis, which are commonly associated with HCC.MethodsWe conducted an analysis of epigenomics in SARS-CoV-2 infection and HCC patients, and identified common pathogenic mechanisms using weighted gene co-expression network analysis (WGCNA) and other analyses. Hub genes were identified and analyzed using LASSO regression. Additionally, drug candidates and their binding modes to key macromolecular targets of COVID-19 were identified using molecular docking.ResultsThe epigenomic analysis of the relationship between SARS-CoV-2 infection and HCC patients revealed that the co-pathogenesis was closely linked to immune response, particularly T cell differentiation, regulation of T cell activation and monocyte differentiation. Further analysis indicated that CD4+T cells and monocytes play essential roles in the immunoreaction triggered by both conditions. The expression levels of hub genes MYLK2, FAM83D, STC2, CCDC112, EPHX4 and MMP1 were strongly correlated with SARS-CoV-2 infection and the prognosis of HCC patients. In our study, mefloquine and thioridazine were identified as potential therapeutic agents for COVID-19 in combined with HCC.ConclusionsIn this research, we conducted an epigenomics analysis to identify common pathogenetic processes between SARS-CoV-2 infection and HCC patients, providing new insights into the pathogenesis and treatment of HCC patients infected with SARS-CoV-2.Supplementary InformationThe online version contains supplementary material available at 10.1186/s13148-023-01515-8.