Oxygen and nitrogen are not greenhouse gases because they do not have dipole moment to get shaken by the infrared electromagnetic wave; and they are transparent to both visible and thermal radiation.
Carbon dioxide, with linear structure, can absorb infrared radiation through the asymmetric vibration of its two oxygen atoms, and thus forms a net dipole moment.
Water vapor, with a bent shape, is an absorber of infrared radiation even when at rest.
Methane absorbs infrared radiation by complicated rotational and vibrational modes, and is a much stronger greenhouse gas than carbon dioxide.
Sulfur dioxide, a molecule like water, carries a partial positive charge and can have a cooling effect in addition to greenhouse gas warming effect through reflecting sunlight.
Hydrogen is diatomic and does not absorb infrared radiation.
Nitrous oxide can be a greenhouse gas too, although its concentration is so small that it doesn’t make much contribution to global warming.
Water vapor plays a complex role in climate change and can lead to positive feedback loops. Some of the water in the atmosphere is in the form of clouds that can block sunlight and contribute to cooling.
Carbon dioxide is the primary contributor to climate change and earth is lucky that its concentration in its atmosphere is low unlike Venus where atmosphere is made of over 95% CO2 with average surface temperature of 464°C.
The atmosphere of earth consists mostly of nitrogen and oxygen. We are fortunate that the most common form these elements take in the atmosphere are diatomic N2 and O2.