This paper investigates the problem of cooperative attitude tracking in the context of fractionated spacecraft free flying that uses electromagnets as relative attitude actuators. The dynamics of the electromagnetic formation flying system is introduced, which shows its inherent nonlinearities and couplings nature. The relative orbit dynamics and attitude kinematics and dynamics are given, the Modified Rodriguez Parameters are used for attitude representation due to its non-reduction. The expected attitude model is presented, then the control law is proposed. The simulation results indicate that the electromagnetic control is a very promising technique for formation flying, the design of the control system is effective, and the attitude tracking control accuracy is better than 0.02°.