Can Bash Tell Me Which SSH Public Key Was Used To Authenticate?
You could add the username to the public key in ~/.ssh/authorized_keys
on the server and export it as an environment value:
environment="REALUSER=realusername" ssh-dsa AAA...
That will set the environment variable REALUSER which will then be available to use in bash. This will only work if PermitUserEnvironment
is set to true in sshd_config