It was determined that the best way to deter this sort of theft was to sit someone beside the driver and arm that person with a loaded shotgun. Nobody likes to be shot, and shotguns are especially mean-looking, so that worked as well as anything. If the shotgun-wielder was large, unattractive, anti-social, and scowled a lot, that was a bonus.
In time, this came to be known as "riding shotgun." Interestingly, there is no evidence that this term was used during the time folks actually were riding shotgun on stage coaches. Instead, it was apparently first used in that context during the first quarter or third of the 1900s.
In time, "riding shotgun" has come to mean riding beside any vehicle's driver, and it may also (less often) refer to simply accompanying someone in order to provide some measure of security - even if there is no actual riding involved.
- Russ Chastain