952 mkdir denyhost
953 cd denyhost/
954 ll
955 wget http://imcat.in/down/DenyHosts-2.6.tar.gz
956 ll
957 tar -zxvf DenyHosts-2.6.tar.gz
958 cd DenyHosts-2.6/
959 ll
960 python setup.py install
[root@edge-node1 ~]# mkdir denyhost[root@edge-node1 ~]# cd denyhost/[root@edge-node1 denyhost]# wget http://imcat.in/down/DenyHosts-2.6.tar.gz[root@edge-node1 denyhost]# tar -zxvf DenyHosts-2.6.tar.gz[root@edge-node1 denyhost]# cd DenyHosts-2.6/[root@edge-node1 DenyHosts-2.6]# python setup.py install[root@edge-node1 DenyHosts-2.6]# cd /usr/share/denyhosts/[root@edge-node1 denyhosts]# cp denyhosts.cfg-dist denyhosts.cfg[root@edge-node1 denyhosts]# vi denyhosts.cfg
再最后加入以下内容:
SECURE_LOG = /var/log/secureHOSTS_DENY = /etc/hosts.denyPURGE_DENY = 1dBLOCK_SERVICE = sshdDENY_THRESHOLD_INVALID = 5DENY_THRESHOLD_VALID = 10DENY_THRESHOLD_ROOT = 3DENY_THRESHOLD_RESTRICTED = 1WORK_DIR = /usr/local/share/denyhosts/dataSUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YESHOSTNAME_LOOKUP=YESLOCK_FILE = /var/lock/subsys/denyhostsHOSTNAME_LOOKUP=NOADMIN_EMAIL = 837448792@qq.comDAEMON_LOG = /var/log/denyhostsDAEMON_PURGE = 10m
[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# cp daemon-control-dist daemon-control[root@edge-node1 denyhosts]# lltotal 112-rw-r--r-- 1 root root 16549 Dec 8 2006 CHANGELOG.txt-rwxr-xr-x 1 root root 4076 Oct 8 23:40 daemon-control-rwxr-xr-x 1 root root 4076 Apr 22 2006 daemon-control-dist-rw-r--r-- 1 root root 22264 Oct 8 23:40 denyhosts.cfg-rw-r--r-- 1 root root 20830 Aug 20 2006 denyhosts.cfg-dist-rw-r--r-- 1 root root 18009 Dec 17 2005 LICENSE.txtdrwxr-xr-x 2 root root 4096 Oct 8 23:38 plugins-rw-r--r-- 1 root root 3575 Feb 3 2006 README.txtdrwxr-xr-x 2 root root 4096 Oct 8 23:38 scripts-rw-r--r-- 1 root root 1522 Apr 5 2006 setup.py[root@edge-node1 denyhosts]# chown root daemon-control[root@edge-node1 denyhosts]# chmod 700 daemon-control[root@edge-node1 denyhosts]# ./daemon-control startstarting DenyHosts: /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfgError processing configuration parameter DENY_THRESHOLD_INVALID: invalid literal for int() with base 10: '5 #\xe5\x85\x81\xe8\xae\xb8\xe6\x97\xa0\xe6\x95\x88\xe7\x94\xa8\xe6\x88\xb7\xe7\x99\xbb\xe5\xbd\x95\xe5\xa4\xb1\xe8\xb4\xa5\xe7\x9a\x84\xe6\xac\xa1\xe6\x95\xb0'[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# lltotal 112-rw-r--r-- 1 root root 16549 Dec 8 2006 CHANGELOG.txt-rwx------ 1 root root 4076 Oct 8 23:40 daemon-control-rwxr-xr-x 1 root root 4076 Apr 22 2006 daemon-control-dist-rw-r--r-- 1 root root 22264 Oct 8 23:40 denyhosts.cfg-rw-r--r-- 1 root root 20830 Aug 20 2006 denyhosts.cfg-dist-rw-r--r-- 1 root root 18009 Dec 17 2005 LICENSE.txtdrwxr-xr-x 2 root root 4096 Oct 8 23:38 plugins-rw-r--r-- 1 root root 3575 Feb 3 2006 README.txtdrwxr-xr-x 2 root root 4096 Oct 8 23:38 scripts-rw-r--r-- 1 root root 1522 Apr 5 2006 setup.py[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# vim denyhosts.cfg[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# ./daemon-control startstarting DenyHosts: /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfgError processing configuration parameter DENY_THRESHOLD_RESTRICTED: invalid literal for int() with base 10: '1 #\xe8\xae\xbe\xe5\xae\x9a deny host \xe5\x86\x99\xe5\x85\xa5\xe5\x88\xb0\xe8\xaf\xa5\xe8\xb5\x84\xe6\x96\x99\xe5\xa4\xb9'[root@edge-node1 denyhosts]# vim denyhosts.cfg[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# ./daemon-control startstarting DenyHosts: /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfgError sending email[Errno 99] Cannot assign requested addressEmail message follows:From: DenyHosts <nobody@localhost>To: 837448792@qq.comSubject: DenyHosts ReportDate: Thu, 08 Oct 2020 23:42:29 +0800Added the following hosts to /etc/hosts.deny:47.94.101.19947.94.206.19----------------------------------------------------------------------[root@edge-node1 denyhosts]# ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts[root@edge-node1 denyhosts]# chkconfig –add denyhostschkconfig version 1.7.4 - Copyright (C) 1997-2000 Red Hat, Inc.This may be freely redistributed under the terms of the GNU Public License.usage: chkconfig [--list] [--type <type>] [name]chkconfig --add <name>chkconfig --del <name>chkconfig --override <name>chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>[root@edge-node1 denyhosts]# chkconfig add denyhostschkconfig version 1.7.4 - Copyright (C) 1997-2000 Red Hat, Inc.This may be freely redistributed under the terms of the GNU Public License.usage: chkconfig [--list] [--type <type>] [name]chkconfig --add <name>chkconfig --del <name>chkconfig --override <name>chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>[root@edge-node1 denyhosts]# chkconfig --add denyhosts[root@edge-node1 denyhosts]# chkconfig denyhosts on[root@edge-node1 denyhosts]# service denyhosts startstarting DenyHosts: /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfgDenyHosts could not obtain lock (pid: 2069)[Errno 17] File exists: '/var/lock/subsys/denyhosts'[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# ps -ef | grep hostroot 2069 1 0 23:42 ? 00:00:00 python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfgroot 2175 1338 0 23:43 pts/1 00:00:00 grep --color=auto host[root@edge-node1 denyhosts]# kill 2069[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# ps -ef | grep hostroot 2189 1338 0 23:43 pts/1 00:00:00 grep --color=auto host[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# service denyhosts startstarting DenyHosts: /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfg[root@edge-node1 denyhosts]# ps -ef | grep hostroot 2204 1 0 23:43 ? 00:00:00 python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfgroot 2208 1338 0 23:43 pts/1 00:00:00 grep --color=auto host[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]#[root@edge-node1 denyhosts]# cat /etc/hosthost.conf hostname hosts hosts.allow hosts.deny[root@edge-node1 denyhosts]# cat /etc/hosts.deny## hosts.deny This file contains access rules which are used to# deny connections to network services that either use# the tcp_wrappers library or that have been# started through a tcp_wrappers-enabled xinetd.## The rules in this file can also be set up in# /etc/hosts.allow with a 'deny' option instead.## See 'man 5 hosts_options' and 'man 5 hosts_access'# for information on rule syntax.# See 'man tcpd' for information on tcp_wrappers## DenyHosts: Thu Oct 8 23:42:29 2020 | sshd: 47.94.101.199sshd: 47.94.101.199# DenyHosts: Thu Oct 8 23:42:29 2020 | sshd: 47.94.206.19sshd: 47.94.206.19
安装DenyHosts-3.1.2
centos8自带的是python3,需要安装较新的DenyHosts-3.1.2,http://denyhosts.sourceforge.net/这个里下载,但需要tizi;
[root@10-0-9-52 /]# mv DenyHosts-3.1.2.tar.gz /data/denyhost/[root@10-0-9-52 /]# cd /data/denyhost/[root@10-0-9-52 denyhost]# lltotal 100drwxr-x--- 6 500 500 4096 Oct 9 17:19 DenyHosts-2.6-rw-r--r-- 1 root root 42667 Dec 8 2006 DenyHosts-2.6.tar.gz-rw-r--r-- 1 root root 53086 Oct 9 17:33 DenyHosts-3.1.2.tar.gz[root@10-0-9-52 denyhost]# tar -zxf DenyHosts-3.1.2.tar.gz[root@10-0-9-52 denyhost]# lltotal 104drwxr-x--- 6 500 500 4096 Oct 9 17:19 DenyHosts-2.6-rw-r--r-- 1 root root 42667 Dec 8 2006 DenyHosts-2.6.tar.gzdrwxr-xr-x 5 root root 4096 May 8 22:38 DenyHosts-3.1.2-rw-r--r-- 1 root root 53086 Oct 9 17:33 DenyHosts-3.1.2.tar.gz[root@10-0-9-52 denyhost]# cd DenyHosts--bash: cd: DenyHosts-: No such file or directory[root@10-0-9-52 denyhost]# cd DenyHosts-3.1.2/[root@10-0-9-52 DenyHosts-3.1.2]# lltotal 112-rw-r--r-- 1 2017 2017 24010 May 8 22:20 CHANGELOG.txt-rwxr-xr-x 1 2017 2017 4834 May 8 22:20 daemon-control-distdrwxr-xr-x 2 root root 4096 May 8 22:38 DenyHosts-rw-r--r-- 1 2017 2017 24489 May 8 22:20 denyhosts.conf-rwxr-xr-x 1 2017 2017 9488 May 8 22:20 denyhosts.py-rw-r--r-- 1 2017 2017 17953 May 8 22:20 LICENSE.txt-rw-r--r-- 1 2017 2017 353 May 8 22:20 MANIFEST.in-rw-r--r-- 1 root root 532 May 8 22:38 PKG-INFOdrwxr-xr-x 2 root root 4096 May 8 22:38 pluginsdrwxr-xr-x 2 root root 4096 May 8 22:38 scripts-rw-r--r-- 1 2017 2017 2120 May 8 22:20 setup.py[root@10-0-9-52 DenyHosts-3.1.2]# vim denyhosts.conf[root@10-0-9-52 DenyHosts-3.1.2]# lltotal 112-rw-r--r-- 1 2017 2017 24010 May 8 22:20 CHANGELOG.txt-rwxr-xr-x 1 2017 2017 4834 May 8 22:20 daemon-control-distdrwxr-xr-x 2 root root 4096 May 8 22:38 DenyHosts-rw-r--r-- 1 2017 2017 24489 May 8 22:20 denyhosts.conf-rwxr-xr-x 1 2017 2017 9488 May 8 22:20 denyhosts.py-rw-r--r-- 1 2017 2017 17953 May 8 22:20 LICENSE.txt-rw-r--r-- 1 2017 2017 353 May 8 22:20 MANIFEST.in-rw-r--r-- 1 root root 532 May 8 22:38 PKG-INFOdrwxr-xr-x 2 root root 4096 May 8 22:38 pluginsdrwxr-xr-x 2 root root 4096 May 8 22:38 scripts-rw-r--r-- 1 2017 2017 2120 May 8 22:20 setup.py[root@10-0-9-52 DenyHosts-3.1.2]# vim daemon-control-dist[root@10-0-9-52 DenyHosts-3.1.2]#[root@10-0-9-52 DenyHosts-3.1.2]#[root@10-0-9-52 DenyHosts-3.1.2]# lltotal 112-rw-r--r-- 1 2017 2017 24010 May 8 22:20 CHANGELOG.txt-rwxr-xr-x 1 2017 2017 4834 May 8 22:20 daemon-control-distdrwxr-xr-x 2 root root 4096 May 8 22:38 DenyHosts-rw-r--r-- 1 2017 2017 24489 May 8 22:20 denyhosts.conf-rwxr-xr-x 1 2017 2017 9488 May 8 22:20 denyhosts.py-rw-r--r-- 1 2017 2017 17953 May 8 22:20 LICENSE.txt-rw-r--r-- 1 2017 2017 353 May 8 22:20 MANIFEST.in-rw-r--r-- 1 root root 532 May 8 22:38 PKG-INFOdrwxr-xr-x 2 root root 4096 May 8 22:38 pluginsdrwxr-xr-x 2 root root 4096 May 8 22:38 scripts-rw-r--r-- 1 2017 2017 2120 May 8 22:20 setup.py[root@10-0-9-52 DenyHosts-3.1.2]# python3 setup.py installrunning installrunning buildrunning build_pycreating buildcreating build/libcreating build/lib/DenyHostscopying DenyHosts/filetracker.py -> build/lib/DenyHostscopying DenyHosts/__init__.py -> build/lib/DenyHostscopying DenyHosts/deny_hosts.py -> build/lib/DenyHostscopying DenyHosts/sync.py -> build/lib/DenyHostscopying DenyHosts/util.py -> build/lib/DenyHostscopying DenyHosts/constants.py -> build/lib/DenyHostscopying DenyHosts/plugin.py -> build/lib/DenyHostscopying DenyHosts/version.py -> build/lib/DenyHostscopying DenyHosts/regex.py -> build/lib/DenyHostscopying DenyHosts/purgecounter.py -> build/lib/DenyHostscopying DenyHosts/prefs.py -> build/lib/DenyHostscopying DenyHosts/daemon.py -> build/lib/DenyHostscopying DenyHosts/restricted.py -> build/lib/DenyHostscopying DenyHosts/loginattempt.py -> build/lib/DenyHostscopying DenyHosts/denyfileutil.py -> build/lib/DenyHostscopying DenyHosts/report.py -> build/lib/DenyHostscopying DenyHosts/lockfile.py -> build/lib/DenyHostscopying DenyHosts/python_version.py -> build/lib/DenyHostscopying DenyHosts/counter.py -> build/lib/DenyHostscopying DenyHosts/allowedhosts.py -> build/lib/DenyHostsrunning build_scriptscreating build/scripts-3.6copying and adjusting denyhosts.py -> build/scripts-3.6copying and adjusting daemon-control-dist -> build/scripts-3.6changing mode of build/scripts-3.6/denyhosts.py from 644 to 755changing mode of build/scripts-3.6/daemon-control-dist from 644 to 755running install_libcopying build/lib/DenyHosts/filetracker.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/__init__.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/deny_hosts.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/sync.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/util.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/constants.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/plugin.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/version.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/regex.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/purgecounter.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/prefs.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/daemon.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/restricted.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/loginattempt.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/denyfileutil.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/report.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/lockfile.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/python_version.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/counter.py -> /usr/local/lib/python3.6/site-packages/DenyHostscopying build/lib/DenyHosts/allowedhosts.py -> /usr/local/lib/python3.6/site-packages/DenyHostsbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/filetracker.py to filetracker.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/deny_hosts.py to deny_hosts.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/sync.py to sync.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/util.py to util.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/plugin.py to plugin.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/purgecounter.py to purgecounter.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/prefs.py to prefs.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/daemon.py to daemon.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/loginattempt.py to loginattempt.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/denyfileutil.py to denyfileutil.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/lockfile.py to lockfile.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/python_version.py to python_version.cpython-36.pycbyte-compiling /usr/local/lib/python3.6/site-packages/DenyHosts/allowedhosts.py to allowedhosts.cpython-36.pycrunning install_scriptscopying build/scripts-3.6/daemon-control-dist -> /usr/local/bincopying build/scripts-3.6/denyhosts.py -> /usr/local/binchanging mode of /usr/local/bin/daemon-control-dist to 755changing mode of /usr/local/bin/denyhosts.py to 755running install_datacopying denyhosts.conf -> /etcrunning install_egg_infoWriting /usr/local/lib/python3.6/site-packages/DenyHosts-3.1.2-py3.6.egg-info[root@10-0-9-52 DenyHosts-3.1.2]# vim /etc/denyhosts.conf
加入以下配置:
SECURE_LOG = /var/log/secureHOSTS_DENY = /etc/hosts.denyPURGE_DENY = 1dBLOCK_SERVICE = sshdDENY_THRESHOLD_INVALID = 5DENY_THRESHOLD_VALID = 10DENY_THRESHOLD_ROOT = 3DENY_THRESHOLD_RESTRICTED = 1WORK_DIR = /usr/local/share/denyhosts/dataSUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YESHOSTNAME_LOOKUP=YESLOCK_FILE = /var/lock/subsys/denyhostsHOSTNAME_LOOKUP=NOADMIN_EMAIL = 837448792@qq.comDAEMON_LOG = /var/log/denyhostsDAEMON_PURGE = 10m
最终启动在安装目录启动:
[root@10-0-9-52 DenyHosts-3.1.2]# ./daemon-control-dist start
