检查使用哪个 SSH 密钥登录

检查使用哪个 SSH 密钥登录

因此,愚蠢的是,在我们的开发团队中,每个单独的 SSH 密钥都用于直接访问 root 用户。

检查 auth.log 时我发现

Dec 18 09:45:04 webserver sshd[12377]: Accepted publickey for root from xx.xx.xx.xx port xx ssh2
Dec 18 09:45:04 webserver sshd[12377]: pam_unix(sshd:session): session opened for user root by (uid=0)

有没有办法查看使用了哪个公钥?也许可以更改日志级别?还是我需要去其他地方查看?

答案1

首先,这是可以做到的。

将 ssh 日志级别更改为 VERBOSE 并重新启动 ssh。通常该文件位于:

nano /etc/ssh/sshd_config

找到 LogLevel 选项并将其更改为 VERBOSE。

LogLevel VERBOSE

重启 SSH 服务

sudo service ssh restart; sudo service sshd restart;

重新连接到 ssh 并检查日志文件。

nano /var/log/auth.log

然后你会发现类似这样的事情:

Dec 23 22:43:42 localhost sshd[29779]: Found matching RSA key: d8:d5:f3:5a:7e:27:42:91:e6:a5:e6:9e:f9:fd:d3:ce

Dec 23 22:43:42 localhost sshd[29779]: Accepted publickey for caleb from 127.0.0.1 port 59630 ssh2

最后,放松一下,不用客气 :)

相关内容