In our current linac-magnetic resonance (MR) design, a 6 MV in-line linac is placed along the central axis of the MR's magnet where the MR's fringe magnetic fields are parallel to the overall electron trajectories in the linac waveguide. Our previous study of this configuration comprising a linac-MR SAD of 100 cm and a 0.5 T superconducting (open, split) MR imager. It showed the presence of longitudinal magnetic fields of 0.011 T at the electron gun, which caused a reduction in target current to 84% of nominal. In this study, passive and active magnetic shielding was investigated to recover the linac output losses caused by magnetic deflections of electron trajectories in the linac within a parallel linac-MR configuration. Magnetic materials and complex shield structures were used in a 3D finite element method (FEM) magnetic field model, which emulated the fringe magnetic fields of the MR imagers. The effects of passive magnetic shielding was studied by surrounding the electron gun and its casing with a series of capped steel cylinders of various inner lengths (26.5-306.5 mm) and thicknesses (0.75-15 mm) in the presence of the fringe magnetic fields from a commercial MR imager. In addition, the effects of a shield of fixed length (146.5 mm) with varying thicknesses were studied against a series of larger homogeneous magnetic fields (0-0.2 T). The effects of active magnetic shielding were studied by adding current loops around the electron gun and its casing. The loop currents, separation, and location were optimized to minimize the 0.011 T longitudinal magnetic fields in the electron gun. The magnetic field solutions from the FEM model were added to a validated linac simulation, consisting of a 3D electron gun (using OPERA-3d/scala) and 3D waveguide (using comsol Multiphysics and PARMELA) simulations. PARMELA's target current and output phase-space were analyzed to study the linac's output performance within the magnetic shields. The FEM model above agreed within 1.5% with the manufacturer supplied fringe magnetic field isoline data. When passive magnetic shields are used, the target current is recoverable to greater than 99% of nominal for shield thicknesses greater than 0.75 mm. The optimized active shield which resulted in 100% target current recovery consists of two thin current rings 110 mm in diameter with 625 and 430 A-turns in each ring. With the length of the passive shield kept constant, the thickness of the shield had to be increased to achieve the same target current within the increased longitudinal magnetic fields. A ≥99% original target current is recovered with passive shield thicknesses >0.75 mm. An active shield consisting of two current rings of diameter of 110 mm with 625 and 430 A-turns fully recovers the loss that would have been caused by the magnetic fields. The minimal passive or active shielding requirements to essentially fully recover the current output of the linac in our parallel-configured linac-MR system have been determined and are easily achieved for practical implementation of the system.