How secure is an airplane on the ground whilst passengers are boarding the aircraft? On my recent flight to Ibiza, as I and the other passengers were boarding, there were many occasions where I could see right into the cockpit as the pilots and cabin crew were communicating back and forth for whatever pre-flight checks they were conducting. Being near the front of the queue at the gate, I was one of the first seated, the 10-20 minutes it took for the rest of the passengers to board was the time I refer to when I say I was able to see into the cockpit.

With it being my first flight in quite a few years, understandably I was extremely nervous. From the open cockpit to the smell of burning as the engines spooled up...

If we ignore terrorism, what is stopping a drunken passenger from, instead of turning right when they board at the front loading door, turn left and take a few steps into the cockpit, and if they were able to get into the cockpit, assuming they know absolutely nothing about the operation of a plane besides that pushing that pushing the throttles forward = more thrust = plane moves (faster), what damage could they do with a plane parked at a jetway or a plane parked out on the tarmac that requires a shuttle to drop passengers to the plane in order to board it.

If we introduce terrorism into the mix, what is stopping a group of strong men from forcing their way into the open cockpit past 1 or 2 cabin crew?
Those guys would gain no more than they'd gain if they hijacked the bus taking you to the airport.

If fact they'd gain less as they'd have nowhere to go and there's a lot more (armed) police at the airport to take them down than there is in some remote place they could drive that bus to.

The greatest risk to airliners isn't people forcing their way into the cockpit on the ground who are among the passengers waiting to board.
It's in the ground crew who can (at least in theory) bring aboard almost anything they wish (including bombs) with very little oversight (in fact this has happened in the past).
And there security has been seriously tightened (and it needed to be) over the decades, making that scenario far harder.
I won't say impossible, because nothing is impossible as long as there is a human factor involved anywhere in the chain, but bloody hard.