You could add a directive to the
authorized_keys entry for a key to add a value to the environment for sessions where that key was used. This is from the sshd documentation:
Specifies that the string is to be added to the environment when logging in using this key. Environment variables set this way override other default environment values. Multiple options of this type are permitted. Environment processing is disabled by default and is controlled via the PermitUserEnvironment option.
So the authorized_keys entry might look like this:
environment="SSHKEY=bob_key" ssh-rsa AAAAB3NzaC...iQ== bob@bobspc
When the user's .bashrc runs, the presence or absence of the SSHKEY variable would indicate whether that particular key was used to authenticate or not.
This is obviously not a general-purpose solution. You'd have to annotate every key entry in every authorized_keys file with this directive. And the user could subvert the check if he had access to alter his