"The people" refers to the militia. Back then, everyone was part of a militia.
Then I suppose "the people" in amendments I, IV, and X also refer to the militia? Of course not. You are correct in pointing out that back then the people were considered the militia, but "the people" still means "the people". The first part of the Second Amendment is explanatory of at least one reason why the right of the people to keep and bear arms should not be infringed, but it is not the part of the amendment that states the law itself. It's a justification for the amendment, nothing more and nothing less. If the Second Amendment was rewritten to be compliant with modern vernacular, it would be something like this:
"The right of the people to keep and bear arms shall not be infringed because a well regulated militia is necessary to the security of a free state."
Militias were very informal during the time the amendment was implemented - they weren't actually regulated by the government, rather they were just local groups ready to fight when an emergency came up. By protecting the right of individual people to keep and bear arms, civilians could (and still can) form militias when necessary, among other things.