A nine-member military tribunal, sitting in Abuja, convicted the soldiers following the incident on May 14 when shots were fired at the commanding officer of the Nigerian Army's 7th Division, which is tasked with fighting Boko Haram insurgents.
Court president Brigadier General Chukwuemeka Okonkwo said the sentences were subject to confirmation by Nigeria's military authorities but added there was no doubt about the gravity of the offence.
The panel considered "its likely effect on the counter-insurgency operations in the northeast as well as its implications on national security", he told the court.
Front-line troops have frequently complained of a lack of adequate weapons and equipment to fight the rebels.
More From This Section
Residents in towns raided by the Islamists have said the insurgents are often armed with rocket-propelled grenades and anti-aircraft weapons mounted on trucks and, in some cases, armoured personnel carriers.
Last month, dozens of Nigerian soldiers refused to deploy for an offensive to try to retake the captured Borno town of Gwoza, which the Islamists claimed as part of an Islamic caliphate.
One of the protesting soldiers, who set up camp on the outskirts of Maiduguri, said at the time: "We are being killed like chickens by Boko Haram because we are not given the required weapons to fight. We say enough is enough."
The country's military spokesman Chris Olukolade denied the troops had mutinied and told AFP that Nigerian soldiers were "too disciplined and patriotic to indulge in this dangerous offence".
President Goodluck Jonathan has asked lawmakers to approve a USD 1 billion foreign loan to upgrade the capacity of the military, which was seen as a tacit acknowledgement that troops were being out-matched.