The magnetic moments of the baryons belonging to the low-lying SU(3) octet are computed using second-order perturbation theory taking into account the effect of the spin-dependent interactions that are expected to arise in quantum chromodynamics. The unperturbed eigenfunctions of the confining Hamiltonian are approximated by harmonic-oscillator wave functions, and the flavor X spin parts belong, in the limit of equal quark masses, to irreducible representations of SU(6). In this basis we then calculate the mixing of the (56, ${0}^{+}$) ground-state wave function with the orbital and radial excitations labeled by (56, ${0}_{R}^{+}$), (70, ${0}^{+}$), (20, ${1}^{+}$), and (70, ${2}^{+}$). This mixing arises not only from the spin-dependent interactions but also from the differences among quark masses. Finally we comment on the contributions to the magnetic moments not taken into account in this work.