Context. The abundances of interstellar CH + and SH + are not well understood as their most likely formation channels are highly endothermic. Several mechanisms have been proposed to overcome the high activation barriers, including shocks, turbulence, and H 2 vibrational excitation. Aims. Using data from the Herschel Space Observatory, we studied the formation of ions, in particular CH + and SH + in a typical high UV-illumination warm and dense photon-dominated region (PDR), the Orion Bar. Methods. The HIFI instrument on board Herschel provides velocity-resolved line profiles of CH + 1-0 and 2-1 and three hyperfine transitions of SH + 1 2 −0 1 . The PACS instrument provides information on the excitation and spatial distribution of CH + by extending the observed CH + transitions up to J = 6-5. We compared the observed line intensities to the predictions of radiative transfer and PDR codes. Results. All CH + , SH + , and CF + lines analyzed in this paper are seen in emission. The widths of the CH + 2-1 and 1-0 transitions are of ∼5 km s −1 , significantly broader than the typical width of dense gas tracers in the Orion Bar (∼2-3 km s −1 ) and are comparable to the width of species that trace the interclump medium such as C + and HF. The detected SH + transitions are narrower compared to CH + and have line widths of ∼3 km s −1 , indicating that SH + emission mainly originates in denser condensations. Non-LTE radiative transfer models show that electron collisions affect the excitation of CH + and SH + and that reactive collisions need to be taken into account to calculate the excitation of CH + . Comparison to PDR models shows that CH + and SH + are tracers of the warm surface region (A V < 1.5) of the PDR with temperatures between 500 and 1000 K. We have also detected the 5-4 transition of CF + at a width of ∼1.9 km s −1 , consistent with the width of dense gas tracers. The intensity of the CF + 5-4 transition is consistent with previous observations of lower-J transitions toward the Orion Bar.Conclusions. An analytic approximation and a numerical comparison to PDR models indicate that the internal vibrational energy of H 2 can explain the formation of CH + for typical physical conditions in the Orion Bar near the ionization front. The formation of SH + is also likely to be explained by H 2 vibrational excitation. The abundance ratios of CH + and SH + trace the destruction paths of these ions, and indirectly, the ratios of H, H 2 , and electron abundances as a function of depth into the cloud.