如何限制云服务器为只能被特定ip ssh连接?

如何限制云服务器为只能被特定ip才能 ssh连接?

阅读 4.1k
4 个回答
  1. iptables限制连入ip

  2. ssh方式:
    比只允许222.38.10.15这个IP进入,其它都禁止:

vim /etc/ssh/sshd_config

添加一行:

allowusers root@222.38.10.15

然后:

service sshd restart

当然root可以换成其他用户

iptables规则

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 1.2.3.4/32 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT

举例:

vim /etc/hosts.allow
sshd:192.168.0.1:allow           //允许IP 192.168.0.1 登录
sshd:192.168.0.:allow            //允许IP 192.168.0.  网段登录 
sshd:all:deny                    //禁止其他的所有IP登录
vim /etc/ssh/sshd_config

加入

Allowusers admin@192.168.0.1

意思为
只允许admin从192.168.0.1登陆

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题