Pepys was a cousin of Edward Montagu. Montagu sided with Parliament during the Civil War, and during Cromwell’s rule Montagu rose to the high command of the Commonwealth Navy. After Cromwell died, Montagu played a part in helping Charles II regain his throne, and was made the Earl of Sandwich as a reward. Sandwich got Pepys a job in the administration of the Navy. Pepys had once rejoiced at the execution of Charles I but became a Royalist at the Restoration.
Pepys worked hard and rose steadily in power, thanks in no small part to the influence of Sandwich, who was able to bring him to the attention of James, Duke of York, the Lord High Admiral, and Charles II. Pepys was a talented administrator. Unfortunately, Pepys took bribes. He didn’t care if the sailors’ food was rancid, since he wasn’t going to eat it; all he wanted was his “gift.” This wasn’t unusual behavior per se, but what it meant was that the sailors were badly fed, and the ships were often in poor condition thanks to Pepys and his cohorts. Over time, Pepys accumulated a large fortune.
Pepys suffered from kidney stones from childhood onwards. He had an operation for one in his teens that left him sterile, though he did not realize this. His poor wife took the blame for their lack of children. His Diary records instances of Pepys beating her. Pepys was serially unfaithful to her as well; some of the women were willing, others not. If you read his Diary, or one of his biographies, you will see what I mean. His diary is available online if you want to read it. A warning: Pepys often used coarse language when he discussed his amours.
Pepys is beloved by many people because he was funny and because he relates a lot of gossip; his Diary is a very human document. His biographers often make excuses for his behavior towards women in general and his wife in particular by saying that it was typical of the era and so forth. Many authors who write about Charles II and James II rely upon Pepys for information. The problem in using Pepys as a source is that he was not writing his Diary for publication, but largely to blow off steam. Pepys relied on hearsay and rumor for information, and even when he was an eyewitness to things, his biases affected his judgment, particularly when his own self-interest was at stake, or that of his cousin and patron Sandwich.
In 1665, Sandwich was put in charge of the summer fleet of the Royal Navy. Sandwich got caught embezzling from some captured prizes. Sandwich got in a lot of trouble, and Pepys hitched his wagon to the star of James, Duke of York, whom he had already been sucking up to for quite some time. Pepys spent time in the Tower during the Popish Plot, was released and eventually reinstated, only to fall from power for good thanks to the Glorious Revolution.
All of this is just my opinion and your mileage may vary.
And so to bed...