这是本文档旧的修订版!


保护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
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

fail2ban

安装 fail2ban 防止攻击 sudo apt-get install fail2ban 2)

it/server/保护.1661620331.txt.gz · 最后更改: 2022-08-27 17:12 由 goldentianya
回到顶部
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0