Green Rim - imaged by Tamás Ladányi (site, TWAN) in Hungary. ©Tamás Ladányi, shown with permission.
The sun has a slight green edge to its upper limb and a red one on the lower. The atmosphere decrases in density away from the surface. Light rays from the sun, moon or stars are refracted as they pass downwrards through the layers of increasing density and refractive index. The resulting ray curvature is towards the greater density and it makes objects in the sky appear slightly higher than they really are. The effect is strongest near the horizon and there it lifts the sun and moon by about 0.5° - their own diameter.
Blue and green light is refracted more strongly than red (dispersion) and the 'green sun' appears higher than the red thus creating a green rim. A blue rim is rare because blue light is more strongly scattered away by the atmosphere.
The green rim is too narrow to be visible to the unaided eye - never, ever, use binoculars or a telescope! - and is only part of the reason that we sometimes see a green flash. Green flashes need the considerable vertical image magnification provided by mirage conditions.