From an airliner, as long as you do not have a checked-in luggage to be delivered at the final destination and the sectors are within the same country then it is hard for the airlines to figure that out (they don't care actually).
How will the airlines finds out? Sometimes, at some airlines, in some sectors there will an airline representative at the plane's door to check the boarding pass during deplaning to make sure only people who should leave at this airport will leave, this happens rarely and usually happens in international flights with more than one sector. Also head counting could reveal this. Again, for domestic flights usually no one checks. Just grab your bags and leave if you want to. In case a representative stopped you at the door and asked you to show your boarding, this is one of the good times to play dumb and say you thought you reached your destination! one more thing, as long as they assigned a representative to check boarding passes this means they don't want to make problems, they just want people who should leave to leave and people who shouldn't leave to stay :)
Is this legal or not? This depends on the country (or state) and airlines rules (I think it is not allowed everywhere). In my country (and I can confirm this in some other countries as well) if you want to leave the plane before you should leave it, it is a problem! you will be questioned and held at the airport until the plane reaches it's final destination. Again, this usually happens for people who come to a flight attendant and ask to be deplaned, such as people with aviophobia who decide to cancel flying at the last moment or people who got a call or something before the departure and ask to leave the airplane.
What to worry about? If you left the plane a sector or two earlier and the plane took off and never landed (crashed)! and you show up alive, you will be the first suspect! Even though this is really unlikely but you have to put this in mind.
I personally have done this many times and left a sector earlier, but I wouldn't tell you to do it or not, you have to decide this yourself. Off the record, it is really unlikely (rare actually) to be caught. I suggest that you talk to the ground agent who will board the aircraft at the stop, ask him nicely and most likely he/she will help.