Overview
"Riding shotgun" was a phrase used to describe the bodyguard who rides alongside a stagecoach driver, typically armed with a break-action shotgun, called a coach gun, to ward off bandits or hostile Native Americans. In modern use, it refers to the practice of sitting alongside the driver in a moving vehicle. The coining of this phrase dates to 1905 at the latest.
Etymology
The expression "riding shotgun" is derived from "shotgun messenger", a colloquial term for "express messenger", when stagecoach travel was popular during the American Wild West and the Colonial period in Australia. The person rode alongside the driver. The first known use of the phrase "riding shotgun" was in the 1905 novel The Sunset Trail by Alfred Henry Lewis.
It was later used in print and especially film depiction of stagecoaches and wagons in the Old West in danger of being robbed or attacked by bandits. A special armed employee of the express service using the stage for transportation of bullion or cash would sit beside the driver, carrying a short shotgun (or alternatively a rifle), to provide an armed response in case of threat to the cargo, which was usually a strongbox. Absence of an armed person in that position often signaled that the stage was not carrying a strongbox, but only passengers.
Historical examples
From Wikipedia (CC BY-SA 4.0).