hosts.allow导致的ssh无法登陆服务器

问题

在服务器上配置了/etc/hosts.allow后无法ssh登陆服务器

vim /etc/hosts.allow 
all:192.10.222.185:allow #test

分析

客户端debug信息

C:\Users\苏>ssh ubuntu@192.10.51.85 -vvv
OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3

debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.10.51.85 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> 'C:\\Users\\\350\213\217/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> 'C:\\Users\\\350\213\217/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: ssh_connect_direct: entering
debug1: Connecting to 192.10.51.85 [192.10.51.85] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_rsa type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ecdsa_sk type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ed25519_sk type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_ed25519_sk-cert type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\\350\213\217/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.6
debug3: recv - from CB(2) ERROR:108, io:00000204B9036800
kex_exchange_identification: read: Connection reset
Connection reset by 192.10.51.85 port 22

服务器log记录与/etc/hosts.allow配置有关

May 21 03:12:35 k8s01 sshd[61778]: error: /etc/hosts.allow, line 21: option "allow" requires no value
May 21 03:12:35 k8s01 sshd[61778]: refused connect from 192.10.222.185 (192.10.222.185)
May 21 03:12:44 k8s01 sshd[62027]: error: /etc/hosts.allow, line 21: option "allow" requires no value
May 21 03:12:44 k8s01 sshd[62027]: refused connect from 192.10.222.185 (192.10.222.185)

/etc/hosts.allow介绍

/etc/hosts.allow 文件是TCP Wrapper功能的一部分,用于控制哪些主机可以访问本机上的网络服务。TCP Wrapper是一种安全机制,通过允许或拒绝来自特定主机的网络服务请求,增强了系统的安全性。hosts.allow 和 hosts.deny 是TCP Wrapper使用的两个重要配置文件。
/etc/hosts.allow 文件格式详解:

  1. 基本结构:/etc/hosts.allow 文件中的每一行定义了一条访问控制规则,格式如下:
service名单: 客户端地址列表 : 行动
  • service名单:代表你希望控制访问权限的网络服务名称,如 sshd 对应SSH服务,smtp
    对应SMTP服务等。你也可以使用通配符ALL来指定所有服务

  • 客户端地址列表:指定了规则适用的客户端IP地址或主机名。这里可以使用单个地址、CIDR表示法的子网、域名或通配符。常见的通配符包括
    ALL(代表任何地址)、LOCAL(代表本机地址)、PARANOID(拒绝看起来像伪造的地址)等。

  • 行动:定义当客户端匹配规则时应采取的行动,默认是允许(ALLOW)。但实际上,由于通常在 hosts.deny
    中定义拒绝规则,hosts.allow 中的规则几乎总是允许(虽然理论上也可以写成 DENY,但这不是常规做法)。

从服务器报错来看如果配置了"行动",后面不能再配置其他内容了,否则语法错误

解决

vim /etc/hosts.allow 
all:192.10.222.185:allow

或者
vim /etc/hosts.allow 
all:192.10.222.185 #test

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值