This could be Empire from the Ashes series of books by David Weber, originally published in 1991.
You can read the first book in the series (Mutineer's Moon) for free online here
"For Colin MacIntyre, it began with a routine training flight over the
moon. For Dahak, a self-aware Imperial battleship, it began millennia
ago, standing guard against an unknown enemy which once devastated the
galaxy-and now has returned. So Dahak grabbed MacIntyre's ship and
informed him that he was drafted to be its new captain and lead the
fight against the ancient enemy.
The moon is a moon-sized spaceship
"It's not possible," MacIntyre said stubbornly. "If this thing is the size you say, what happened to the real moon?" "It was destroyed," his
informant said calmly. "With the exception of sufficient of its
original material to make up the negligible difference in diameter, it
was dropped into your sun. It is standard Fleet procedure to
camouflage picket units or any capital ship that may be required to
spend extended periods in systems not claimed by the Imperium."
camouflaged your ship as our moon? That's insane!" "On the contrary,
Commander. A planetoid-class starship is not an easy object to hide.
Replacing an existing moon of appropriate size is by far the simplest
means of concealment, particularly when, as in this case, the original
surface contours are faithfully recreated as part of the procedure."
He's made Emperor as part of an attempt to hack into a battle computer;
"Damn it. Damn it! We need an emperor to get into the goddamned system, and the last > emperor died forty-five thousand years ago!"
"Captain," Dahak said after a moment, "I believe there might be a way."
"Colin screamed in the grip of an agony too vast to endure, and yet it was over before he > could truly experience it. Its echoes shuddered
away down his synapses, stuttering in the racing pound of his heart,
and then they were gone.
"Case Omega executed," Mother said emotionlessly. "The Emperor is dead; long live the Emperor!" "