Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I want to track my root users. Each of them has a unique private key and their public keys have been stored in /root/.ssh/authorized_keys.

Given that each user logs in with their unique key how can I tell from within a BASH session which key was used to authenticate? I've tried looking at the environment variables when I log in but cannot see anything that correlates my session with my public key.

share|improve this question
Slightly related: setting LogLevel VERBOSE in your (openssh) sshd_config will log the fingerprint of the key used to login. – andol Apr 6 '14 at 15:02

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

share|improve this answer
Whoah.. really? Cool! You mean in ~/.ssh/authorized_keys? I never knew about this. – PP. Sep 20 '13 at 10:17
Yep, that's it. You can do a whole lot of interesting things there - man ssh will tell you more under the heading AUTHORIZED_KEYS FILE FORMAT. – Jenny D Sep 20 '13 at 10:19
It might depend on the version, but I had to use man sshd to find the AUTHORIZED_KEYS FILE FORMAT section. – Matthew Crumley Sep 20 '13 at 15:06
Be aware that enabling PermitUserEnvironment has some security implications. Read man sshd – Florin Andrei Nov 15 '14 at 1:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.