SSH限制ip登陆

linux限制IP访问ssh

 

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

 

更改端口
vi /etc/ssh/sshd_config
port 3333


最后一行加上ip
allowusers root@ip   ------------------允许某个ip用什么帐户登陆

 

实际示例:

复制代码
cat /etc/hosts.allow 
#
# hosts.allow    This file contains access rules which are used to
#        allow or deny connections to network services that
#        either use the tcp_wrappers library or that have been
#        started through a tcp_wrappers-enabled xinetd.
#
#        See 'man 5 hosts_options' and 'man 5 hosts_access'
#        for information on rule syntax.
#        See 'man tcpd' for information on tcp_wrappers
#
sshd:192.168.0.0/24:allow 
sshd:172.20.18.0/24:allow 
sshd:10.8.0.0/24:allow 
复制代码
复制代码
 cat /etc/hosts.deny 
#
# hosts.deny    This file contains access rules which are used to
#        deny connections to network services that either use
#        the tcp_wrappers library or that have been
#        started through a tcp_wrappers-enabled xinetd.
#
#        The rules in this file can also be set up in
#        /etc/hosts.allow with a 'deny' option instead.
#
#        See 'man 5 hosts_options' and 'man 5 hosts_access'
#        for information on rule syntax.
#        See 'man tcpd' for information on tcp_wrappers
#
sshd:ALL
复制代码

systemctl restart sshd

验证只能内网登录 ,外网无法登录

 

 

posted @   Oops!#  阅读(2597)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示