Yes but not like a car key.
On the B747s I worked on there was a key to the cockpit door and on combi models there was a key to the main-deck cargo compartment (same key). I still have one somewhere, it's brass and has Boeing stamped on it. These were distributed within the company and all our B747s used the same key.
On the ATR there is also a key for the pax doors but in my airline this is not used as there are ramp guards.
These keys will not stop someone who knows his way around airplanes as there are other panels which can be opened from the outside . Some airlines/authorities required the pax steps/bridge to be removed from unattended widebody aircraft but its common for mechs to access via the avionics compartment. I've never seen a key on these doors.
A more common procedure is to seal all doors and access panels (sticker seals) so that any unauthorised access will be visible and further steps can be taken.. (added checks etc).