Linux系统禁止IP登录

在/etc/hosts.allow输入  
  (其中192.168.10.88是你要允许登陆ssh的ip,或者是一个网段192.168.10.0/24)  
  sshd:192.168.10.88:allow  
   
  在/etc/hosts.deny输入(表示除了上面允许的,其他的ip都拒绝登陆ssh)  
  sshd:ALL
***************************************************************************
比如说你只允许1.1.1.1这个IP进入,其它都禁止:  
方法1、iptables。  
  iptables   -A   INPUT   -s   1.1.1.1   --destination-port   22   -j   ACCEPT  
  iptables   -A   INPUT   --destination   22   -j   DROP  
改正:
iptables -A INPUT -p tcp -s   1.1.1.1   --destination-port   22   -j   ACCEPT  
iptables -A INPUT -p tcp --destination-port   22   -j   DROP 

方法2:  
  vi   /etc/ssh/sshd_config  
  添加一行:  
  allowusers xxx@1.1.1.1 或AllowUsers sysman@192.168.125.* 
  注:xxx为你用来登入服务器的用户名。
***************************************************************************
方法一:

在/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 

方法三:

用 iptables 也行:
iptables -I INPUT -p tcp --dport 22 -j DROP
iptables -I INPUT -p tcp --dport 22 -s 1.2.3.4 -j ACCEPT

2,禁止某个用户通过ssh登录
在/etc/ssh/sshd_conf添加
AllowUsers 用户名
或者
AllowGroups 组名
或者
DenyUsers 用户名

3,设定登录黑名单
vi /etc/pam.d/sshd
增加
auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/sshd_user_deny_list onerr=succeed

所有/etc/sshd_user_deny_list里面的用户被拒绝ssh登录

下面简单实现Linux 下限制SSH登录IP
/etc/hosts.allow

sshd:192.168.0.100:allow //允许IP 192.168.0.100 登录
sshd:192.168.10.:allow //允许IP 192.168.10. 网段登录
sshd:all:deny //禁止其他的所有IP登录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值