How a generator makes electricity?

A generator works by producing mechanical energy using an engine, which can be powered using a variety of fuel options such as diesel, biogas, natural gas or LPG. The engine is used to rotate the axle of an electrical conductor in a magnetic field which creates electricity.

Engine - the engine is used to create mechanical energy.

Alternator (or genhead) - creates the electrical output from the engine generated mechanical energy. 

The mechanical energy is used to rotate a copper coil wrapped around an iron core inside powerful a permanent magnet or electric magnet. This movement, or changing magnetic field, causes electrons in the conducting (copper) wire to move from one place to another creating an electrical current.



Ref - https://www.eia.gov/energyexplained/index.php?page=electricity_generating, https://www.explainthatstuff.com/generators.html, https://www.originenergy.com.au/blog/about-energy/what-is-electricity.html