denyhosts / denyhosts

Automated host blocking from SSH brute force attacks
GNU General Public License v2.0
679 stars 124 forks source link

The Ubuntu deb Python 3.x package is being installed in Python 2.7 dist-packages. #209

Open cnobile2012 opened 2 years ago

cnobile2012 commented 2 years ago

Yup, the title says it all, however even after I physically moved it to the correct place (/usr/local/lib/python3.8/dist-packages/) it still gets this error when starting the daemon.

$ sudo service denyhosts start Failed to start denyhosts.service: Unit denyhosts.service not found.

It does work if run manually: sudo /usr/local/bin/daemon-control start. See my comment below for a fix to this 2nd issue.

I had to manually create the symlinks for /etc/init.d/denyhosts.

Also, the daemon-control tries to use Python2.7, it should be using Python 3.x. I have installed Python 3.8.10

So sum up:

  1. DEB package put the python files in the wrong place.
  2. The startup script fails to start on Ubuntu systems.
  3. daemon-control tries to use Python2.7
cnobile2012 commented 2 years ago

I found a fix for the second issue above. This should be put at the start of the script right after the #!/usr/bin/python3.

#!/usr/bin/python3

### BEGIN INIT INFO
# Provides:          denyhosts
# Required-Start:    $local_fs $remote_fs $syslog $named $network $time
# Required-Stop:     $local_fs $remote_fs $syslog $named $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Activates/Deactivates the DenyHosts daemon
# Description:       Activates/Deactivates the DenyHosts daemon to block ssh attempts
### END INIT INFO

# denyhosts     Bring up/down the DenyHosts daemon
#
# chkconfig: 2345 98 02
# description: Activates/Deactivates the
#    DenyHosts daemon to block ssh attempts
#
###############################################

You'll notice I moved the python imports below the comments for both REL and Ubuntu systems.

So instead of using # chkconfig --add denyhosts which doesn't work on Ubuntu, use sudo update-rc.d denyhosts defaults from within the /etc.init.d/ directory.

See https://help.ubuntu.com/community/UbuntuBootupHowto The docs are a bit old, but still seems to work even for Ubuntu 20.04

qs5779 commented 2 years ago

The package shared here in assets seems hard coded for python 2. I also seems very outdated. You may be interested in my comment for issue https://github.com/denyhosts/denyhosts/issues/213