The FileVault recovery key is a long code that unlocks your Mac’s disk when the password won’t. If it ended up somewhere it shouldn’t be, like a screenshot or a note that syncs everywhere, you don’t have to switch FileVault off and on again. You can swap the key for a new one.
This is the command:
sudo fdesetup changerecovery -personal
It asks you to authenticate, and then generates a new personal recovery key and replaces the old one. A Mac can only have one personal recovery key, so the old key is removed the moment the new one is made. On APFS volumes (macOS 10.14 and later) you can authenticate with the existing recovery key, which is handy if the reason you’re doing this is a password problem.
A good moment for this is when you suspect someone saw the key, or when you’re tidying up after years of copying it between password managers. My advice is to have your password manager open before you press Enter, because the new key is shown in Terminal and you’ll want to store it right away.
To check afterwards that a key is in place:
sudo fdesetup haspersonalrecoverykey
The catch: the old key stops working right away. Any copy you kept on paper or in a vault is useless after this, so replace it everywhere. And if your Mac is managed by a company, leave this alone, since the IT department may escrow that key and a key you rotate yourself won’t match what they have on file.
Further reading: fdesetup man page, Manage FileVault in the Apple deployment guide