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
3. 统计以root或者其它用户登录的次数
sudo grep "Failed password for root" /var/log/auth.log | wc -l sudo grep "Failed password for invalid user" /var/log/auth.log | wc -l
进去后更改一下root用户密码,并切换到root用户,然后修改 /etc/ssh/sshd_config 文件,免除密码登录。重启ssh服务
sudo systemctl restart ssh
sudo systemctl restart sshd
sudo service ssh restart
// 统计以 root 用户尝试登录到数量 sudo grep "Failed password for root" /var/log/auth.log | wc -l // 统计以其它用户试登录到数量 sudo grep "Failed password for invalid user" /var/log/auth.log | wc -l
PasswordAuthentication no PermitRootLogin yes PubkeyAuthentication yes // 允许公钥登录 RSAAuthentication yes ChallengeResponseAuthentication no //使用命令重启 ssh 服务: sudo /etc/init.d/ssh restart
将公钥复制到服务器,密码登录一次。验证完公钥登录后,关闭密码登录 PasswordAuthentication no 所有人都无法用密码登录了。
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ps -e |grep ssh
查看是否启动ssh服务,
使用的密码身份验证PAM(在所有现代系统上)是由ChallengeResponseAuthentication选项处理的,yes默认情况下。质询响应认证指定是否允许质询-响应身份验证(例如,通过 PAM)。默认值为“是”。将它添加到您的sshd_configwith value no,重新启动,它将为您工作: 这在示例中多次提到sshd_config。
# If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. ChallengeResponseAuthentication no
如果依然可以密码登录,则是 You can disable keyboard-interactive by setting KbdInteractiveAuthentication to “no” 的原因。
安装 fail2ban 防止攻击 sudo apt-get install fail2ban
2)
检查状态 sudo iptables --list -n
解锁ssh fail2ban-client set sshd unbanip <ip>
或者更改 /etc/fail2ban/jail.conf 文件,为某些IP设置白名单。
添加对nginx 和 wordpress 的保护 mkdir -p /root/wwwlogs
然后重启服务