Temporary access has a habit of becoming permanent. For a key that belongs to a contractor or a short project, I like the end date on the key line itself.
The option goes in front of the key in ~/.ssh/authorized_keys:
expiry-time="20270131" ssh-ed25519 AAAAC3Nza... guest@example
From that moment sshd refuses the key. The format is YYYYMMDD or YYYYMMDDHHMM, with optional seconds. The man page says the time is read in the server’s time zone, unless you add a Z at the end for UTC:
expiry-time="202701311700Z" ssh-ed25519 AAAAC3Nza... guest@example
You can combine it with other options, separated by commas, for instance with from= to also limit where the key may log in from.
Keep in mind the line stays in the file after it expires. It does nothing anymore, but cleaning those up now and then keeps the file honest about who really has access. And this only covers the key. If that person also has a password or another key on the account, expiry-time does not touch those.
Further reading: sshd man page, AUTHORIZED_KEYS FILE FORMAT