knockd.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 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. # patch https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=868015
  36. # TODO this line is buggy
  37. echo "
  38. # patch https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=868015
  39. [Install]
  40. WantedBy=multi-user.target
  41. Alias=knockd.service" >> /lib/systemd/system/knockd.service
  42. systemctl enable knockd
  43. systemctl start knockd
  44. echo -e "\033[92;1mknockd installed and configured\033[Om"
  45. echo -e "\033[92;1mplease note this sequence for future ssh knocking\033[Om"
  46. echo "$sq"
  47. sleep 3