这是本文档旧的修订版!
保护VPS
查看受到的攻击
VPS 会遭到各种攻击1)
1.查看尝试暴力破解机器密码的人
sudo grep "Failed password for root" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | more cat /var/log/auth.log // 或者第二种方式
2.查看暴力猜用户名的人
sudo grep "Failed password for invalid user" /var/log/auth.log | awk '{print $13}' | sort | uniq -c | sort -nr | more
禁止密码登录
进去后更改一下root用户密码,并切换到root用户,然后修改 /etc/ssh/sshd_config 文件,免除密码登录。重启ssh服务
sudo systemctl restart ssh
sudo systemctl restart sshd
sudo service ssh restart
PasswordAuthentication no PermitRootLogin yes PubkeyAuthentication yes // 允许公钥登录 RSAAuthentication yes //使用命令重启 ssh 服务: /etc/init.d/ssh restart
将公钥复制到服务器,密码登录一次。验证完公钥登录后,关闭密码登录 PasswordAuthentication no 所有人都无法用密码登录了。
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
fail2ban
安装 fail2ban 防止攻击 sudo apt-get install fail2ban
2)