The ghosts have been introduced in the formalism of calculating proper vertex functions to cancel the contribution from unphysical pieces of the gauge fields.
Take, as the most simple example, QED, i.e., the (un-Higgsed) U(1) gauge theory describing a Dirac field ("electrons and positrons") interacting through a minimally coupled U(1) gauge field ("photons"). First you start with four gauge fields.
The physical meaning is in the asymptotic free states, and as you well know, what's described with them are free photons being composed in terms of momentum-helicity single-photon Fock states. Of these only the 2 helicity states are physical, i.e., two field degrees of freedom are unphysical already in the sense of asymptic free states.
Now when calculating higher-order corrections (loops in Feynman diagrams) you formally sum also over the unphysical states, and this is on the first glance fatal, because it means you sum over states which have a negative norm, and the so calculated naive S-matrix wouldn't be unitary and also the microcausality condition may does not hold.
The path-integral formalism then shows that the correct way is to integrate over one physical field configuration only once and not over the infinitely many possibilities describe one and the same state expressed in different "gauges". So you choose a gauge-fixing condition and make sure by an appropriate functional ##\delta## distribution that you only pick out the one gauge configuration subject to this constraint. However, this is not so easily implemented in terms of a perturbative treatment, and that's why you use the trick to integrate over the gauge group and then expressing the arising functional determinant in the pertinent path-integral measure in terms of also unphysical Faddeev Popov ghost fields (which are formally scalar fields but implemented in the path integral as Grassmann fields, because the corresponding functional Jacobi determinant is in the numerator rather than the denominator), and these exactly cancel the contributions from the unphysical states of the gauge field.
In QED the Faddeev-Popov ghosts in the usual linear gauges are non-interacting and thus can be omitted, but that's not so for the non-Abelian case.
For details, see my QFT notes:
https://itp.uni-frankfurt.de/~hees/publ/lect.pdf