
SSH防暴力破解的解决方法:
1、禁止root用户ssh登陆;
1.1、修改PermitRootLogin项:
[root@localhost ~]# vi /etc/ssh/sshd_config
[root@localhost ~]# grep Root /etc/ssh/sshd_config
PermitRootLogin no ### 将默认的 #PermitRootLogin yes 修改成这样的 ###
# the setting of "PermitRootLogin without-password".
[root@localhost ~]# vi /etc/ssh/sshd_config
[root@localhost ~]# grep Root /etc/ssh/sshd_config
PermitRootLogin no ### 将默认的 #PermitRootLogin yes 修改成这样的 ###
# the setting of "PermitRootLogin without-password".
1.2、重启sshd服务
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
2、修改ssh默认端口22;
2.1、将默认端口22修改为自定义的2020端口
[root@localhost ~]# vi /etc/ssh/sshd_config
[root@localhost ~]# grep Port /etc/ssh/sshd_config
Port 2020
#GatewayPorts no
[root@localhost ~]# vi /etc/ssh/sshd_config
[root@localhost ~]# grep Port /etc/ssh/sshd_config
Port 2020
#GatewayPorts no
2.2、在防火墙中加入2020端口的策略
[root@localhost ~]# vi /etc/sysconfig/iptables
[root@localhost ~]# grep 2020 /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2020 -j ACCEPT
[root@localhost ~]# vi /etc/sysconfig/iptables
[root@localhost ~]# grep 2020 /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2020 -j ACCEPT
2.3、重启防火墙策略
[root@localhost ~]# /etc/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: nat filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
[root@localhost ~]# /etc/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: nat filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
2.4、重启sshd服务
[root@localhost ~]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
vi /etc/ssh/sshd_config,找到Port 22,然后将端口22改为你想要的端口号,重启SSH服务:/etc/init.d/sshd restart即可,然后测试ssh连接:ssh localhost -p 你的端口号,连接成功。如果你希望保险起见,不至于因为一个端口连接不了(比如受到攻击)而不能使用ssh连接,那么你可以使用多个ssh连接端口,还是在配置文件/etc/ssh/sshd_config中修改,运行vi /etc/ssh/sshd_config,找到Port 端口号地方,然后在下面添加一行:Port 23,这样就又增加了一个新的连接端口,重启SSH服务,
测试ssh localhost -p 23,连接成功。
另外需要注意的是,如果本机测试没有问题,但还是不能使用第三房工具从外部SSH链接的话,需要关闭防火墙
,重新启动一下SSHD。 这样就可以。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)