The answer depends on what kind of aircraft you're talking about, and how much control the crew has over the pressurization systems.
For example, in theory you could very well reduce or completely shut off the air to the cabin on a 777 .
This could also be done by a single crew member alone.
The pilots have full control of this system should say the one of the engines produce bad air to that cabin and would needed to be switched off.
As for the oxygen masks-
these are for emergency descent use and have a generator that runs out after about 15 minutes.
The crew bottles last a bit longer I think, but these will also have a limit, and doing any attempt to break through the bullet-proof cockpit door in those conditions I'd imagine would be very difficult, since I'm not sure you're still picking up the amount of oxygen you normally would.
For a similar situation (though not a deliberate attempt) you can read up on Helios Airways Flight 522 .
For an idea of how the pilot masks look, see this video .
Source: SmartCockpit
aviation.stackexchange.com/users/790/Thunderstrike
Yes, I think it would be very easy for the pilot in command of a 777 to do this — here's one scenario: Ask the copilot to get a glass of water and lock the cockpit door behind him Don and activate the oxygen mask
Close the engine
bleed air valves that supply
cabin pressure Open the controlled outflow valves to equalize cabin pressure to altitude pressure
Put the passenger/supernumerary oxygen to "reset" (or pull the circuit breaker)
Ascend a little bit above the service ceiling of FL 410.
At FL 450, consciousness is measured in seconds, death in about 4 or 5 minutes.
aviation.stackexchange.com/users/1553/Ramon Tinio
Very simple operation
and you don't need to be at 41,000 feet to do it.
Anything above about 21,000 feet
and you die in a few minutes; you just fall asleep.
If you are really paying attention, you would first notice your fingernails (under them) will turn blue due to a lack of oxygen first.
A few giggles perhaps
, then you'd pass out and DIE.
Quite painlessly actually.
aviation.stackexchange.com/users/1634/joe
The answer is yes: if one of the pilots needed to use the restroom, regulations require the other pilot to put on his O2 mask while the other pilot is away.
Once outside the cockpit, the other pilot could lock the door and the other pilot out.
Then he could turn everything off.
Also since it was at about 1:30am, most passengers would be trying to sleep in their chairs; additionally the masks that drop only have enough O2 to last while the aircraft descends to a lower/safer altitude — so if the plane maintained altitude, there would only be 5-10 minutes of O2 and everyone would pass out and eventually die.
Unless it landed on smooth water, like the miracle on the Hudson, the plane's ELT (Emergency Locator Transmitter) would go off and the crash site would be pinpointed by satellites within seconds.
So therefore one of two things happened:
It landed on water softly and is now at bottom of ocean, or; It landed safely on land because there was no ELT signal.
aviation.stackexchange.com/users/1628/David Airline pilot
Depressurization leads not only to the lack of oxygen in the cabin (and cockpit), but likewise may lead to a dramatic drop in temperature.
For altitudes above 38,000 - 65,000 feet, the outside temperature is roughly -70°F/-55°C.
Combined with data suggesting that at 40,000 feet a passenger sitting quietly would retain consciousness for only about 18 seconds with the loss of oxygen from depressurization (and thus presumably fewer seconds at 45,000 feet), it may only be a matter of seconds, not minutes, before everyone in the cabin would be dead.
What I don't know and wish I did know is whether the cabin and cockpit have separate pressurization systems.
I assume so.
This would make it even easier for a pilot to incapacitate/kill all crew and passengers.
aviation.stackexchange.com/users/1568/user1568
Could a pilot of an airliner incapacitate everyone outside the cockpit by somehow triggering a loss of cabin pressure while simultaneously disarming the airplane's oxygen masks, manipulating the air circulation system to induce hypoxia, or some other means?  For example, would it be a credible theory that the pilot de-pressurized the 777 flying  Malaysia Airlines Flight 370  and flew it off somewhere?
Could a pilot incapacitate other crew/passengers by manipulating cabin air quality/pressure?
aviation.stackexchange.com
<aircraft-design><cabin-pressure><boeing-777><mh370-incident><hypoxia>
aviation.stackexchange.com/questions/2328
aviation.stackexchange.com/users/972/Yarin
 The pilots have full control of this system. Should one of the engines produce bad air to that cabin and need to be switched off. if one of the pilots needed to use the restroom, regulations require the other pilot to put on his O2 mask while the other pilot is away. While it is a bit more complicated, it seems that a pilot can actually mess with the systems that control the air in a cabun but only if there is a way to secure himself.
It is suggested that the pilot can manipulate the functioning of the systems that regulate the oxygen.