Ssh – temporarily disable login using one specific ssh key

authenticationopensshpublic-key-authenticationssh

On my server, I have several public SSH keys in ~/.ssh/authorized_keys.

I would like to temporarily block/disallow/deactivate one key. I want to prevent the user to log in using this key now. but I might want to reanable it later (i.e. I don't want to delete the key entirely).

What is the correct/recommended way to do it?

Shall I just put a comment # at the beginning of the line in authorized_keys, in front of the key?

To clarify, I don't want to block a specific user. One user account is shared among several people, each person connecting with his own SSH key. I want to block one specific SSH key.

Best Answer

You could prefix the key with a forced command that tells the user what's going on. For example:

command="/usr/bin/printf '*** Your key has been disabled ***\r\n'; sleep 1",no-pty,no-port-forwarding ssh-rsa AAAAB2...19Q== joe@example.net

Then they get:

$ ssh servername
PTY allocation request failed on channel 0
Your key has been disabled
Connection to lxdns101 closed.
Related Question