I'm going to write a book based on a true story. I want to know if for a book cover I could use real photos of the people who were in that story. They are dead but their pictures are published on the Internet.
Photographs belong to the photographer (or to a business which has a contract with the photographer such that they own the copyright). It makes no difference if the subject is alive or dead.
A lot of stuff on the internet doesn't have proper attribution. You will need to track down the copyright holder.
If the picture is in the public domain, you don't have to get permission to use it. But don't assume it's in the public domain just because a site says so, or because someone used it on their site.
If the picture has an active copyright, you need to get permission from the copyright owner. As a general rule, you will have a written contract stating that you are allowed to use the picture in XYZ context and that you will pay a certain amount. Always get it in writing.