An electromagnetic active control device for longitudinal vibration of a marine shafting, belonging to the technical field of oceanographic engineering, comprises: an acceleration transducer, a tachometer, a signal analysis and control module, a power amplifier and an electromagnetic actuator, wherein the acceleration transducer and the tachometer are respectively located on a thrust bearing base and a middle shaft and output a measured vibration acceleration electric signal of the base and a photoelectric signal of the shafting to the signal analysis and control module; the signal analysis and control module receives the vibration acceleration electric signal and the photoelectric signal, performs spectrum analysis and characteristic signal extraction on the received signals to generate corresponding action control signals, and outputs the action control signals to the power amplifier for amplification; and the electromagnetic actuator is arranged on the middle shaft and receives the amplified control signals to generate a corresponding longitudinal actuation force applied on the middle shaft, thereby implementing the control for the longitudinal vibration of the shafting. The electromagnetic active control device for longitudinal vibration of the marine shafting effectively reduces the longitudinal vibration of the shafting, so that vibration response of a marine structure is reduced finally, and the control device not only is effective to low frequency line spectra, but also has excellent control effect on broadband random excitation.