The ‘keys of death and hades’ (Rev. 1:18 (ESV); ‘keys of hell and death’ (KJV)) are a metaphor for authority over death and the grave.
Sometimes in the Bible ‘keys’ represent authority. For example, in Isaiah 22:22 God says the following about Eliakim:
…I will place on his shoulder the key of the house of David. He shall open, and none shall shut; and he shall shut, and none shall open.
The context of Isa. 22:22 shows Eliakim is being given the authority to govern the Jews — the ‘key of the house of David’ symbol represents this authority (he didn’t literally get a key on his shoulders; but he was given authority to govern the Jews).
The Book of Revelation is a book full of symbols, as many other prophetic books are, and the symbol of ‘keys’ — which represents authority or control — is in Revelation. Rev. 9:1-2, for example, says the following:
{1} And the fifth angel blew his trumpet, and I saw a star fallen from heaven to earth, and he was given the key to the shaft of the bottomless pit. {2} He opened the shaft of the bottomless pit, and from the shaft rose smoke like the smoke of a great furnace, and the sun and the air were darkened with the smoke from the shaft.
This picture language has an angel being given a key, which he then uses to open a bottomless pit. Because the angel has the key to the bottomless pit he has control over the bottomless pit. Rev. 20:1-3 has an angel locking things in the bottomless pit, too — the angel has control over the pit. Keys represents control over something.
So, we come to Rev. 1:17-18:
{17} When I saw him [Jesus], I fell at his feet as though dead. But he laid his right hand on me, saying, “Fear not, I am the first and the last, {18} and the living one. I died, and behold I am alive forevermore, and I have the keys of Death and Hades.
This passage records Jesus speaking and he describes himself as the ‘living one’ — i.e. he has been raised from the dead and made immortal: he is ‘alive forevermore’. Because he has been raised from the dead and is immortal he has been given authority/control over death and hades (i.e. the grave). This is exciting and comforting news for Christians: Jesus has control over the grave so, even if we die before he returns to the earth (Acts 1:11), he can open the grave and free us from death when he returns (1Thess.4:16) — Jesus can resurrect us and give us immortality!