在我的hosts.allow结束时,我有以下几点:
ALL : ALL \ : spawn (echo "%d" | /usr/bin/mail -s "tcpf\: %d attempt from %h." root) & \ : severity auth.info \ : twist /bin/echo "You are not welcome to use %d from %h."`
但是,这似乎只是把这个文本放到我的auth.log中:
mail sshd[63546]: twist 12.34.56.789 to /bin/echo "You are not welcome to use sshd from 12.34.56.789."
在客户端,我只看到“由远程主机closures连接”,我没有看到回声的输出。 man -k twist没有任何东西 – man -k twist
hosts_options(5)的手册页解释了tcp_wrappers中的twist命令:
twist shell_command执行
hosts_access(5)手册页中所述的%扩展之后,将当前进程replace为指定shell命令的实例。 Stdin,stdout和stderr连接到客户端进程。 该选项必须出现在规则的末尾。
问题是,SSH不仅仅是一个文本协议,但期望一些协议消息,如果它没有收到它们,它会失败。 如果你要以debugging模式( ssh -v )运行ssh ,你会看到以下内容:
debug1: Local version string SSH-2.0-OpenSSH_7.5 debug1: ssh_exchange_identification: You are not welcome to use sshd from ::1. ssh_exchange_identification: read: Connection reset by peer
所以这个消息是真的发送的,但是由于它是不正确的SSH横幅,它失败了。 如何将消息注入到ssh协议中没有简单的方法。 您可能需要接受这种行为。