krlaboratories

SSH security cheatsheet

Dec 22nd, 2021 (edited)
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. 1 - Change default port
  2.  
  3. nano /etc/ssh/sshd_config // need uncomment Port22 and put other number, then CTRL+O
  4.  
  5. iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport XXXXX -j ACCEPT
  6. systemctl restart iptables // add security inbound access rule for new port
  7.  
  8. sudo systemctl restart ssh.service  // for Debian/Ubuntu
  9. sudo systemctl restart sshd.service // for CentOS
  10.  
  11. ssh -p XXXXX user@server
  12.  
  13. 2 - Setup Authentification
  14.  
  15. You should disable PasswordAuthentication and only allow access using PubkeyAuthentication to improve brute-force SSH security.
  16.  
  17. You should disable UseDNS by editing /etc/ssh/sshd_config and setting:
  18. UseDNS no
  19. Otherwise, lfd will be unable to track SSHD login failures successfully as the log files will not report IP addresses
Advertisement
Add Comment
Please, Sign In to add comment