Keyes was born in Brimfield, Massachusetts. While still a youth, he moved with his family to Kennebec County, Maine. Although his father, Justus, was renowned as a physician and surgeon, Erasmus decided to pursue a military career and enrolled in the United States Military Academy. He graduated 10th out of a class of 45 in 1832, and was commissioned a brevetsecond lieutenant in the 3rd U.S. Artillery. Keyes served in Charleston Harbor during the nullification crisis of 1832-33, and served as an aide to General Winfield Scott from 1837 to 1841. Keyes was promoted to captain on November 30, 1841. He served in various garrisons until 1844 and then functioned as an artillery and cavalry instructor at West Point. During 1844, he was a member of the Academy's Board of Visitors. After his service at West Point, he was then sent with the 3rd U.S. Artillery Regiment in 1854 around Cape Horn to California and served on the Pacific frontier in garrison duty and campaigns until 1860. While there Keyes served in the Pacific Northwest from the winter of 1855 in the Puget Sound War. Keyes's artillery Company M was sent to Fort Steilacoom. While there, in January 1856, he made two attempts to capture Chief Leschi but without success. March 4, 1856, he and 100 Regulars fought a skirmish at the White River and Muckleshoot Prairie. During the Spokane – Coeur d'Alene – Paloos War Captain Keyes was sent ahead with a detachment of dragoons to establish Fort Taylor and a ferry crossing the Snake River for Colonel George Wright's army. In the following campaign he commanded four companies of rifle armed artillerymen against the allied tribes at the Battle of Four Lakes. Shortly after this battle, Keyes received his commission of major on October 12, 1858. General Scott appointed Keyes his military secretary on January 1, 1860, a position Keyes filled until April 1861.
Civil War
At the outbreak of the Civil War, Keyes was promoted to colonel of the 11th U.S. Infantry on May 14, 1861. He then served briefly on the staff of New York Governor Edwin D. Morgan until June 25, 1861, overseeing that state's raising of militia. At the First Battle of Bull Run, Keyes commanded the 1st Brigade, 1st Division, and then led Keyes's Brigade, before assuming command of a division from November 9, 1861, to March 13, 1862. In August 1861 he was promoted to the rank of brigadier general of volunteers with date of rank of May 17, 1861, the third-ranking brigadier general in the Army. On March 14, 1862, President Lincoln issued an order forming the Army of the Potomac into corps, Keyes receiving command of the new IV Corps. When Maj. Gen. George B. McClellan's Peninsula Campaign against Richmond was organized in the spring of 1862, Keyes led in unexceptionable fashion. Keyes saw action at Lee's Mill, Yorktown, Bottom's Bridge, Savage's Station, Seven Pines, Charles City Cross Roads, Malvern Hill, and Harrison's Landing. For gallantry at Fair Oaks, Keyes received the brevet of brigadier general in the regular army. After the Seven Days Battles, McClellan promoted all his corps and division commanders to the rank of major general, aside from Keyes, who did not receive a promotion and remained a brigadier general. When the army returned to Washington D.C. in early August, Keyes and one of the two IV Corps divisions were permanently left behind on the Peninsula as part of General John Dix's Department of the James. On March 12, 1863, President Abraham Lincoln nominated Keyes for promotion to the grade of major general, U.S. Volunteers, to rank from May 5, 1862 and the U.S. Senate confirmed the award on March 13, 1863. In addition to the IV Corps, he commanded the Yorktown District, VII Corps, and the division at Suffolk. Among Keyes's other actions were the raid to White House, Virginia, on January 7, 1863, and the expedition to West Point, Virginia, on May 7, 1863. During the Gettysburg Campaign in 1863, Keyes fell afoul of General John Adams Dix's strategic plan to demonstrate heavily against Richmond in order to divert Confederate reinforcements from General Robert E. Lee's army in Pennsylvania. Keyes retreated from a position near what is now Talleysville, Virginia, in the face of what Dix deemed to be inferior forces, so Dix had Keyes removed from command. Although Keyes asked for an investigation of the charges that led to his removal, the request was never granted. He then served on various boards and commissions, including the board for retiring disabled officers from July 15, 1863, until his resignation and retirement from the army on May 6, 1864.
Postbellum activities
Following his war service, Keyes moved to San Francisco, where he soon became financially successful and prominent. He converted to Catholicism in San Francisco in 1866. He was president of a Mexican gold mining company in 1867-1869, and vice president of the California vine-culture society from 1868 to 1872. He also was engaged in the savings and loan business. General Keyes became a member of the California Commandery of the Military Order of the Loyal Legion of the United States - a military society of Union officers and their descendants. Keyes was the author of The Rear Guard at Malvern Hill as part of The Century Company's Battles and Leaders of the Civil War series, as well as Fifty Years' Observation of Men and Events. This was later reprinted as Fighting Indians in Washington Territory. His work From West Point to California was published posthumously in 1950. While on a trip to Europe with his wife, Keyes died in Nice, France, at age 85. He is buried in West Point Cemetery.