knockd.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # TODO check if root
  3. echo -e '
  4. _ __ _
  5. | |/ /_ _ ___ __| |__
  6. | . <| . \/ _ \/ _| / /
  7. |_|\_\_||_\___/\__|_\_\
  8. '
  9. echo -e "Installing knockd to control ssh port opening"
  10. . bin/checkroot.sh
  11. # get the current position
  12. _cwd="$(pwd)"
  13. # check for assets forlder
  14. _assets="$_cwd/assets"
  15. if [ ! -d "$_assets" ]; then
  16. _assets="$_cwd/../assets"
  17. if [ ! -d "$_assets" ]; then
  18. echo "!! can't find assets directory !!"
  19. exit
  20. fi
  21. fi
  22. sleep 2
  23. apk add knock
  24. echo -n "checking if ufw is installed"
  25. ufw_installed=$(apk list -I | grep "ufw")
  26. if ! $ufw_installed; then
  27. echo -n "ufw installed"
  28. else
  29. . bin/ufw.sh
  30. fi
  31. mv /etc/knockd.conf /etc/knockd.conf.ori
  32. cp "$_assets"/knockd.conf /etc/knockd.conf
  33. echo -n "define a sequence number for opening ssh (as 7000,8000,9000) : "
  34. read sq
  35. sed -i "s/7000,8000,9000/$sq/g" /etc/knockd.conf
  36. rc-update add knockd
  37. /etc/init.d/knockd start
  38. ufw delete allow ssh
  39. echo -e "knockd installed and configured"
  40. echo -e "please note this sequence for future ssh knocking"
  41. echo "$sq"
  42. sleep 3