您的位置:首页 > 运维架构 > Linux

如何限制IP,通过SSH登陆linux服务器

2016-09-15 20:04 369 查看
原文链接:
http://www.t086.com/article/4828
方法一:

在/etc/hosts.allow中添加允许ssh登陆的ip或者网段   

sshd:192.168.1.2:allow 或者

sshd:192.168.1.0/24:allow 

在/etc/hosts.deny添加不允许ssh登陆的IP

sshd:ALL           #ALL表示除了上面允许的,其他的ip 都拒绝登陆ssh

方法二:

使用iptables。  

iptables -A INPUT -p tcp -s 192.168.1.2 --destination-port 22 -j ACCEPT

iptables -A INPUT -p tcp --destination-port 22 -j DROP 

方法三:

修改ssh配置文件

vi /etc/ssh/sshd_config

添加一行:

allowusers xxx@192.168.1.2 

注:xxx为你用来登入服务器的用户名。

PS: 当然可以顺便改一下默认端口22

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux ssh