The invention belongs to a chemical technology and the technical field of a renewable energy source, and relates to a method for producing second-generation biodiesel by hydrogenation production of illegal cooking oil. The method comprises the following steps: firstly, carrying out pretreatments such as filtering, dewatering and desalting, on the collected illegal cooking oil; respectively carrying out reaction, such as hydrodeoxygenation, hydrogenation decarboxylation and hydrogenation decarbonylation, in the presence of a transition metal phosphide catalyst so as to obtain the second-generation biodiesel. By adopting the method, the noble metal property and excellent hydrogenation performance of the transition metal phosphide are fully utilized, the illegal cooking oil is directly converted into oxygen-free fat alkanes, no byproduct for polluting the environment is generated, meanwhile, the method has the advantages of simple process, is clean and environmental, low in energy consumption and the like, the obtained diesel is high in cetane number and low in condensation point, has good economic and social benefits, and has important practical significance on growing fuel requirements.