I know about the Apollo pooping bag. The question is, in the CSM, was there any space to use it privately? I suppose while coasting towards the Moon they could use the LM, but on the return trip? Any one of the equipment bays maybe? And while on the moon, in the LM, two astronauts were crammed in it almost touching each other. Did they poo in front of each other? Or was the LM ever pressurized for only one astronaut? Or did they only go in their suits?
The question is, in the CSM, was there any space to use it privately? I suppose while coasting towards the Moon they could use the LM, but on the return trip?
The lower equipment bay of the CM was a semi-private place to do one's business. The defecation bags were stored there, and the urinary relief tubes were also located there. The LM was not used; it was kept closed off during the outbound trip.
And while on the moon, in the LM, two astronauts were crammed in it almost touching each other. Did they poo in front of each other?
They would not if they could avoid it. They ate a "low-residue", high-protein diet, and took a drug called lomotil to minimize bowel movements.
Even the three-day lunar stays of the later Apollo missions were manageable this way. According to Jim Lovell, Frank Borman attempted to go without a bowel movement for the entire two weeks of the Gemini 7 mission (where he and Lovell were confined to a cramped cockpit no larger than the LM cabin) but finally surrendered to the call of nature after nine days. (He had less success on Apollo 8: he suffered a bout of gastroenteritis and consequent diarrhea on the outbound trip.)
They did poop, and with some privacy (see below).
The other answers are correct about the low-residue diet and Lomotil, but that still didn't stop them from having bowel movements. Table 2 of this NASA page provides an inventory of Apollo bowel movements (including the weight of each, in case you care). Some flights has as few as 3, and one mission had 16.
While wearing spacesuits, they wore a Fecal Containment System (diaper):
Inside the spacecraft, they preferred to use the Fecal Collection Assembly. Their uniform had a "back door" (which the astronauts complained was too small). They would stick the adhesive rim of the bag on their buttocks, do their business, wipe with a disinfecting cloth, place it in a disposal bag with a germicidal liquid, knead the bag to mix the germicide, and then put it in a stowage bin.
On the lunar module, there was barely enough room to take their suits off. They turned their backs to each other during bowel movements.
As Russell already stated, they used the lower equipment bay when in the command module.
Understandably, the astronauts preferred to poop in privacy. However, maybe it would have been a good idea to help each other, as it would have avoided situations such as this one:
133:29:52 Stafford (onboard): Give me a napkin quick, there's a turd floating through the air.
133:29:55 Young (onboard): I didn't do it. It ain't one of mine.
133:29:57 Cernan (onboard): I don't think it's one of mine.
133:29:59 Stafford (onboard): Mine was a little more sticky than that. Throw that away.
133:30:06 Young (onboard): God almighty.
4$\begingroup$ The "stowage bins" were returned to Johnson Space Center. I had the privilege of working with an individual whose job was to transport them. $\endgroup$ Nov 26, 2018 at 22:11
3$\begingroup$ At least he wasn't the one who had to weigh them! $\endgroup$ Nov 26, 2018 at 23:05
$\begingroup$ I would have been smart and weighed them in space... just write down 0.0! There's a bit of related discussion in the Vintage Space video Broken Space Toilets mean Floating Fecal Dust $\endgroup$– uhohMay 17, 2019 at 4:36
According to https://space.stackexchange.com/a/31987/18085, Armstrong and Aldrin, before landing on the moon, took a pill to inhibit bowel movements. That doesn't say they never had to defecate, but it does indicate it was not considered a fun thing to do in the tight confines of the LM.
7$\begingroup$ that's ok cause Armstrong and Aldrin were mere hours on the Moon, but further missions stayed longer, up to three days for Apollo 17. $\endgroup$– dronkitNov 22, 2018 at 22:39
$\begingroup$ @dronkit Actually I meant to add my answer as a comment (but erred), because as you point out it doesn't really address your question. I hope someone is able to supply a good answer to replace mine. $\endgroup$ Nov 23, 2018 at 1:08