Advertisement
jandrusk

Harden SSH

Apr 5th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.89 KB | None | 0 0
  1. #!/bin/sh
  2. SSH_DIR=/etc/ssh
  3. # unalias cp rm mv
  4. cd $SSH_DIR
  5. cp ssh_config ssh_config.tmp
  6. cat $SSH_DIR/ssh_config.tmp | grep -v Protocol | sed '$a\\nProtocol 2'
  7. > $SSH_DIR/ssh_config
  8. rm ssh_config.tmp
  9. cp sshd_config sshd_config.tmp
  10. awk '/^#? *Protocol/ { print "Protocol 2"; next };
  11. /^#? *X11Forwarding/ \
  12. { print "X11Forwarding yes"; next };
  13. /^#? *IgnoreRhosts/ \
  14. { print "IgnoreRhosts yes"; next };
  15. /^#? *RhostsAuthentication/ \
  16. { print " RhostsAuthentication no"; next };
  17. /^#? *RhostsRSAAuthentication/ \
  18. { print "RhostsRSAAuthentication no"; next };
  19. /^#? *HostbasedAuthentication/ \
  20. { print "HostbasedAuthentication no"; next };
  21. /^#? *PermitRootLogin/ \
  22. { print "PermitRootLogin no"; next };
  23. /^#? *PermitEmptyPasswords/ \
  24. { print "PermitEmptyPasswords no"; next };
  25. /^#? *Banner/ \
  26. { print "Banner /etc/issue.net"; next };
  27. {print}' sshd_config.tmp > sshd_config
  28. rm sshd_config.tmp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement