In this study, a novel strain of L. fermentum JF9 with bacteriocin production capacity was firstly isolated from Chinese fermented vinegar Pei, and the significant antibacterial potential and safety of L. fermentum JF9 were confirmed by three-generation whole genome sequencing. The bacteriocin Fermencin B2, secreted by L. fermentum JF9, was purified by series chromatographic separation and LC-MS/MS. Fermencin B2, a cationic peptide containing the HLVRNP amino acid sequence, exhibited a stable β-folded structure and antibacterial activity at different temperatures. Meanwhile, Fermencin B2 had low cytotoxicity and was not hemolytic. The inhibitory activity and mechanisms of Fermencin B2 against S. aureus were investigated using SEM and TEM analysis, molecular docking analysis, assays for membrane proteins and ion levels, nucleic acids, LDH leakage, as well as flow cytometry. Fermencin B2 caused severe damage to the cell membrane of S. aureus, resulting in the disruption of ATPase activity, alteration of ion transport, increased membrane permeability, and disintegration of the cell membrane. This ultimately led to the leakage of nucleic acids and LDH, resulting in bacterial death. Overall, Fermencin B2 could be a novel antibacterial agent and food preservative for targeted inhibition of S. aureus.