我创build了一个shell脚本,询问连接的用户一个问题,然后给他提示。 shell将问题发布到数据库进行日志logging。 问题是我们的开发人员正在使用共享帐户,但是每个用户都有私钥。 有没有什么方法可以用shell脚本(bash)读取连接用户的公钥?
在Unix和Linux SE上有类似的提示。 考虑到这一点,你可以grep你的日志中的最新条目连接IP:
REMOTE_IP=${SSH_CONNECTION%% *} grep -B1 ${REMOTE_IP} /var/log/auth.log
假设你正在使用debian,sshd日志转到auth.log 。 如果使用像发行版一样的RH他们将在secure.log 。
您可以通过在/etc/ssh/sshd_config设置LogLevel指令来将sshd日志logging级别提升为VERBOSE
LogLevel DEBUG
这会导致sshd为每个连接logging以下内容
Aug 17 12:16:20 centos sshd[9587]: Connection from 192.168.254.200 port 58107 Aug 17 12:16:20 centos sshd[9587]: Found matching RSA key: 54:d2:06:cf:85:ac:89:f6:3c:a8:73:c7:a1:30:c2:8b Aug 17 12:16:20 centos sshd[9588]: Postponed publickey for user from 192.168.254.200 port 58107 ssh2 Aug 17 12:16:20 centos sshd[9587]: Found matching RSA key: 54:d2:06:cf:85:ac:89:f6:3c:a8:73:c7:a1:30:c2:8b Aug 17 12:16:20 centos sshd[9587]: Accepted publickey for user from 192.168.254.200 port 58107 ssh2 Aug 17 12:16:20 centos sshd[9587]: pam_unix(sshd:session): session opened for user user by (uid=0)
环境variablesSSH_CONNECTION包含当前连接的信息
192.168.254.200 58107 192.168.254.89 22 <sourece IP> <source port> <destination IP> <destination port>
通过一些脚本,应该可以把两者拉在一起。