This question already has an answer here:

I need to get the users public key, that was used to authenticate the current ssh session.

Running env only shows:

SSH_CLIENT= 35538 22

marked as duplicate by Archemar, RalfFriedl, Thomas, Jeff Schaller, thrig Sep 16 '18 at 16:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    How about reading from ~/.ssh/id_rsa.pub? – Panki Sep 11 '18 at 10:47
  • I am interested, what will you use it for? – ctrl-alt-delor Sep 11 '18 at 10:57
  • @Panki what if you have several public key and you rely on a ssh.conf that you cannot manage yourself. also ~/.ssh/id_rsa.pub is not readable from your ssh connection. – Kiwy Sep 11 '18 at 12:50
  • Do you have access to the sshd logs? It's confusing, because you seem to be asking how to find the ssh key that you just used (as that user). – Jeff Schaller Sep 11 '18 at 13:08
  • Potentially useful: serverfault.com/a/888300/293440 – Jeff Schaller Sep 11 '18 at 13:11