ubuntusshsshd

Can you get the remote IP during SSH AuthorizedKeysCommand execution?


Is it possible to get the incoming IP address of an SSH connection before the connection is authorized?

We're using an AuthorizedKeysCommand bash script that is working as intended, but I would like to be able to at least log attempts including the incoming IP address. I've been unable to find anything that would even vaguely hint that it's available. Environment variables like $SSH_CLIENT and $SSH_CONNECTION are empty in the script, and there are no tokens available in the sshd config that contain IP.

The authorized keys script is pretty simple.

#!/bin/bash
curl -sf -X GET "http://10.x.x.x/gatekeeper/$1/$IP_WOULD_GO_HERE"

Solution

  • It looks like you've mostly answered the question yourself: that value isn't available as a token nor as an environment variable. Your remaining option is to log the connection somewhere outside of sshd itself: