安全防火墙denyhosts简单应用
下载
wget -c https://sourceforge.net/projects/denyhosts/files/latest/download
unzip denyhosts-3.0.zip
mv denyhosts-3.0 denyhosts
cd denyhosts
安装
# 由于系统自带python3而不是python 先创建软链接
ln -s /usr/bin/python3 /usr/bin/python
# 安装
python setup.py install
修改配置入口文件
daemon-control-dist
DENYHOSTS_BIN = "/opt/local/denyhosts/denyhosts.py"
DENYHOSTS_LOCK = "/var/run/denyhosts.pid"
DENYHOSTS_CFG = "/opt/local/denyhosts/denyhosts.conf"
配置开机自启
创建文件 /usr/lib/systemd/system/denyhosts.service
[Unit]
Description=SSH log watcher
Before=sshd.service
[Service]
Type=forking
ExecStartPre=/bin/rm -f /var/run/denyhosts.pid
ExecStart=/opt/local/denyhosts/denyhosts.py --daemon --config=/opt/local/denyhosts/denyhosts.conf
PIDFile=/var/run/denyhosts.pid
[Install] WantedBy=multi-user.target
# 设置开机自启
systemctl enable denyhosts.service
# 重载系统服务配置文件
systemctl daemon-relaod
# 启动
systemctl start denyhosts.service
# 查看
systemctl status denyhosts.service
配置项说明
- SECURE_LOG:指定 SSH 日志文件的位置。
- HOSTS_DENY:指定将阻止的 IP 写入的文件路径。
- PURGE_DENY:设置被阻止 IP 的清除时间。
- BLOCK_SERVICE:指定要阻止的服务名称。
- DENY_THRESHOLD_INVALID:允许无效用户登录失败的次数。
- DENY_THRESHOLD_VALID:允许普通用户登录失败的次数。
- DENY_THRESHOLD_ROOT:允许 root 用户登录失败的次数。
- WORK_DIR:DenyHosts 运行时的工作目录。
- SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS:是否允许可疑登录报告的主机。
- HOSTNAME_LOOKUP:是否进行域名反解析。
- LOCK_FILE:记录 DenyHosts 进程 ID 的文件路径。
- ADMIN_EMAIL:管理员邮件地址,用于告警通知。
- SMTP_HOST、SMTP_PORT、SMTP_FROM、SMTP_SUBJECT:邮件服务器相关配置,用于发送告警邮件。
- DAEMON_LOG:DenyHosts 自身的日志文件路径。
- DAEMON_SLEEP:后台运行时,读取日志文件的时间间隔。
- DAEMON_PURGE:清除机制的时间间隔。
问题
- 启动成功但总提示:Can't open PID file /run/denyhosts.pid (yet?) after start: Operation not permitted。
标题:安全防火墙denyhosts简单应用
作者:codercyf
地址:https://soloblog.ccstudy.cc/articles/2025/01/08/1736346924665.html