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.
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.