Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #225990

Re: ssh key used for login

From <tomas@tuxteam.de>
Newsgroups linux.debian.user
Subject Re: ssh key used for login
Date 2020-08-07 21:10 +0200
Message-ID <ABfUC-2He-23@gated-at.bofh.it> (permalink)
References <ABcDn-An-1@gated-at.bofh.it> <ABcN3-DL-1@gated-at.bofh.it> <ABec9-1Ce-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Aug 07, 2020 at 07:09:34PM +0200, Rainer Dorsch wrote:
> Am Freitag, 7. August 2020, 17:47:31 CEST schrieb john doe:
> > On 8/7/2020 5:07 PM, Rainer Dorsch wrote:
> > > Hi,
> > > 
> > > can anybody tell if there is a way to find out the ssh key (out of the
> > > ones
> > > listed in authorized keys) was used for login to the current session?
> > 
> > Try to increase the log verbosity to 'debug[1|2|3]'.
> > 
> 
> Thanks for the reply, but it seems my question was not precise enough.
> 
> I want to find it out in a script which runs on the server, e.g.
> 
> ssh server.domain myscript.sh
> 
> Is there a way to find out in myscript.sh which ssh key was used for login. 
> 
> There are a number of ssh environment vars, but none of them contains the ssh 
> key (or even better the "user label" after the public key):
> 
> declare -x SHLVL="1" 
> declare -x SSH_CLIENT="192.168.7.203 56018 22" 
> declare -x SSH_CONNECTION="192.168.7.203 56018 192.168.7.1 22" 
> declare -x SSH_TTY="/dev/pts/2"

The ssh(1) man page says, in the section "ENVIRONMENT":

  SSH_USER_AUTH  Optionally set by sshd(8), this variable may contain
                 a pathname to a file that lists the authentication
                 methods successfully used when the session was established,
                 including any public keys that were used.

so you need to convince sshd to do that trick for you. In sshd_config, you have

  ExposeAuthInfo
          Writes a temporary file containing a list of authentication
          methods and public credentials (e.g. keys) used to authenticate
          the user.  The location of the file is exposed to the user
          session through the SSH_USER_AUTH environment variable.  The
          default is no.

So perhaps those are the bricks you need. Note that I haven't tried it out.

Cheers
 - t

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

ssh key used for login Rainer Dorsch <ml@bokomoko.de> - 2020-08-07 17:40 +0200
  Re: ssh key used for login john doe <johndoe65534@mail.com> - 2020-08-07 17:50 +0200
    Re: ssh key used for login Rainer Dorsch <ml@bokomoko.de> - 2020-08-07 19:20 +0200
      Re: ssh key used for login <tomas@tuxteam.de> - 2020-08-07 21:10 +0200
  Re: ssh key used for login Kushal Kumaran <kushal@locationd.net> - 2020-08-08 02:30 +0200
    Re: ssh key used for login echo test <echotest09@gmail.com> - 2020-08-08 16:50 +0200
    Re: ssh key used for login Rainer Dorsch <ml@bokomoko.de> - 2020-08-09 22:00 +0200

csiph-web