OpenSSH 8.9 (and probably others lower and higher) will display the public key when run with LogLevel DEBUG2
in /etc/ssh/sshd_config
.
But: OpenSSH limits the length of its log lines to 500 characters silently, so you need to patch it in most cases to get the full key.
The patch I used with my installation on Ubuntu is below:
diff --git a/log.c b/log.c
index bdc4b6515..09474e23a 100644
--- a/log.c
+++ b/log.c
@@ -325,7 +325,7 @@ log_redirect_stderr_to(const char *logfile)
log_stderr_fd = fd;
}
-#define MSGBUFSIZ 1024
+#define MSGBUFSIZ 8192
void
set_log_handler(log_handler_fn *handler, void *ctx)
@@ -417,7 +417,7 @@ do_log(LogLevel level, int force, const char *suffix, const char *fmt,
closelog_r(&sdata);
#else
openlog(progname, LOG_PID, log_facility);
- syslog(pri, "%.500s", fmtbuf);
+ syslog(pri, "%.8192s", fmtbuf);
closelog();
#endif
}
--
The giveaway if you're seeing the full lines is whether the log line - which starts with debug2: userauth_pubkey: valid user someusername querying public key
(where someusername is the authenticating user) ends with the string [preauth]
. ECC-DSA keys are probably short enough to fit, but RSA keys definitely aren't.