Never in its history has the military been quite so squeamish about sex.

American society is, of course, openly obsessed with sex. But the military — long a bastion of randy soldiers and raging hormones — is moving swiftly in the opposite direction. Its discomfort with copulation exploded into public view with the recent firing of the captain of the USS Enterprise aircraft carrier on the eve of its deployment to support the war in Afghanistan.

In 2006 and 2007, Capt. Owen Honors starred in a series of shipboard videos in which he pantomimed masturbation and peered into showers at pairs of semi-clothed men and women. Within 48 hours of the bawdy videos surfacing on the Internet, Honors was sent packing.

He left in good company. About half of the 17 Navy skippers who lost their commands last year were fired for sexual dalliances. The Army and the Marine Corps have similarly adopted zero-tolerance policies for any kind of sexual indiscretion. These days, battlefield commanders are far more likely to lose their jobs for marital infidelity than for martial failings.

“With the Americans, it was quite extraordinary,” said Emma Sky, a British civilian who spent several years working as an adviser to top American commanders in Iraq. “As a woman, I found the U.S. military to be one of the best places to work because they had completely removed sex from the equation. It is the most un-sexist environment I have ever worked in.”

Still, the military’s extreme sexlessness in the midst of so much killing left Sky a bit uncomfortable. “It is not quite natural,” she said. “It really is a bizarre moral code. I would joke with them that they were a bunch of Christian jihadis.”

The sex habits of soldiers, sailors and Marines may seem like a trifling matter amid the travails of battle. But the sexual mores are emblematic of a growing gulf between a military focused on fighting in Iraq and Afghanistan, and a society that is increasingly losing interest in the distant conflicts. No other major wars in U.S. history have been fought with a smaller percentage of America’s citizens in uniform — there are roughly 2.4 million active and reserve troops in a country of more than 300 million, making up less than 1 percent of the population.

The military’s isolation in rural mega-bases and the increasingly hereditary nature of service have further compounded the distance between soldiers and society. “My big fear is that we’ll have a military that is essentially a speck of Sparta in the midst of Babylon,” said retired Army Maj. Gen. Robert Scales. “I worry the military will become an institution that has essentially excepted itself out of society.”

Sky cites a similar concern. “Americans have placed their Army on a pedestal,” she said. “You want your military to be of and from the people, and not above them.”

The military’s leadership wasn’t always expected to be quite so monastic. In the early 1930s, Gen. Douglas MacArthur returned to Washington from the Philippines with a 16-year-old girl whom he installed in a hotel on 16th St. NW, according to a biography by historian Geoffrey Perret.

When a syndicated columnist started to ask questions about his underage lover, MacArthur reportedly told his aide, then-Maj. Dwight D. Eisenhower, to get her out of town. “I like to tell my students that on the plains of West Point we have a statue honoring a statutory rapist and another statue to someone who aided and abetted him,” said Lt. Col. Robert Bateman, a military historian.

During World War II, prostitutes were often forced to undergo examinations by military doctors in an effort to keep soldiers healthy. Along those lines, Gen. George S. Patton famously opined that “a man who won’t [expletive], won’t fight.”

As late as the 1980s, officers’ clubs on military bases in the United States and abroad regularly featured performances by strippers. “I think we used to call them exotic dancers,” Scales recalled. Today the officers’ club at Fort Campbell, Ky., home to the legendary 101st Airborne Division, was recently reopened as a Family Resource Center where soldiers and their spouses can get marriage and financial counseling. There are full-time babysitters on site.

What caused the changes?

First, there are more women in the military than ever: They make up 20 percent of the Air Force, 16 percent of the Navy, 14 percent of the Army and 7 percent of the Marines.

As women in uniform have taken on positions of greater authority, the military has reacted by pretending that sex in the ranks doesn’t exist, wrote retired Capt. Kevin Eyer in this month’s issue of the U.S. Naval Institute’s flagship magazine, Proceedings. “You cannot put men and women in a small box, send them away for extended periods of isolated time, and expect them not to interact with one another,” he concluded. “They’re like magnets . . . they stick. It is what has kept our species going for 250,000 years.”

Even the word “woman” has fallen out of favor on Army and Marine posts. Instead the military prefers “females,” which refers to non-male troops, and “ladies,” a term that encompasses wives and the women who work in the base’s protocol office orthrift store.

The shift in military sexual mores also coincided with an increasing number of evangelical Christians who began moving into the officer corps in the 1980s, as well as the 1991 Tailhook scandal, in which hundreds of naval and Marine aviators’ careers were scuttled by allegations of sexual harassment and abuse at a Las Vegas hotel.

Finally, the wars in Iraq and Afghanistan have fueled the military’s turn away from sex. In both countries, alcohol and pornography are prohibited on the grounds that they offend Muslims. Soldiers and Marines in Afghanistan are repeatedly told not to look at local women.

Meanwhile, some Western women find themselves covering up even on U.S. bases. “I did not even like going to a gym in a sleeveless workout top,” said Erin Simpson, who recently returned from a stint as a civilian counterinsurgency adviser to the Army and Marine Corps. “A lot of these guys haven’t seen their wives or girlfriends in a year. It makes you a little maladjusted.”

To be sure, much of the military’s extreme sexlessness is a facade. Troops still sneak off for intimate liaisons on forward operating bases or ships. In Iraq and Afghanistan, soldiers and Marines frequently make arrangements for friends to wipe their computers clean of pornography if they are killed in battle so that their mothers and wives won’t see the offending images when their laptops are shipped home.

Recently, the comic strip “Doctrine Man,” written by an anonymous active-duty officer and distributed via Facebook, spoofed the military’s obsession with confiscating porn.

“You can’t bring pornography through Navy customs,” a military customs officer tells a Marine returning from Iraq in a short animation.

“It is illegal for me to bring pornography back into the U.S.?” the Marine asks. “I thought this was where most of the pornography was made.”

“Do you think you’d catch the Greatest Generation coming through here with porn?” the customs officer presses.

“[Expletive] yeah,” the Marine replies.

Of course, the military’s almost cultish embrace of a warrior-monk ideal has some plus sides. Most military experts believe that it will make the integration of openly gay troops into the ranks much easier. “The military will have no problem with homosexuals because it is a sexless environment,” Sky said. “It just won’t be an issue.”

Greg Jaffe covers military affairs for The Washington Post and is a co-author of “The Fourth Star: Four Generals and the Epic Struggle for the Future of the United States Army.”