$\overline{\rm MS}$-on-shell quark mass relation up to four loops in QCD and a general SU$(N)$ gauge group