knockd.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. # TODO check if root
  3. echo -e '\033[35m
  4. __ __ __
  5. / /______ ____ _____/ /______/ /
  6. / //_/ __ \/ __ \/ ___/ //_/ __ /
  7. / ,< / / / / /_/ / /__/ ,< / /_/ /
  8. /_/|_/_/ /_/\____/\___/_/|_|\__,_/
  9. \033[0m'
  10. echo -e "\033[35;1mInstalling knockd to control ssh port opening\033[0m"
  11. if [ "$EUID" -ne 0 ]; then
  12. echo "Please run as root"
  13. exit
  14. fi
  15. # get the current position
  16. _cwd="$(pwd)"
  17. # check for assets forlder
  18. _assets="$_cwd/assets"
  19. if [ ! -d "$_assets" ]; then
  20. _assets="$_cwd/../assets"
  21. if [ ! -d "$_assets" ]; then
  22. echo "!! can't find assets directory !!"
  23. exit
  24. fi
  25. fi
  26. sleep 2
  27. apt-get --yes --force-yes install knockd
  28. mv /etc/knockd.conf /etc/knockd.conf.ori
  29. cp "$_assets"/knockd.conf /etc/knockd.conf
  30. echo -n "define a sequence number for opening ssh (as 7000,8000,9000) : "
  31. read sq
  32. sed -i "s/7000,8000,9000/$sq/g" /etc/knockd.conf
  33. sed -i 's/START_KNOCKD=0/START_KNOCKD=1/g' /etc/default/knockd
  34. # /etc/init.d/knockd start
  35. systemctl start knockd
  36. # patch https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=868015
  37. # systemctl enable knockd
  38. echo -e "\033[92;1mknockd installed and configured\033[Om"
  39. echo -e "\033[92;1mplease note this sequence for future ssh knocking\033[Om"
  40. echo "$sq"
  41. sleep 3