我有几个具有以下sshd配置的服务器。
# Authentication:
PermitRootLogin no
AllowGroups ssh
PubkeyAuthentication yes
PasswordAuthentication no
这意味着“ ssh”组中的每个用户都可以登录,但只能使用pubkey登录。不允许登录root。
但是root必须有一个例外:我的$ ip备份服务器必须以root用户身份登录。
我试过了:
AllowUsers root@$ip
AllowGroups ssh
但是AllowUsers会覆盖AllowGroups语句。因此,只有$ ip的root用户才能登录。
Match User root, Address $ip
PermitRootLogin {yes|without-password}
AllowUsers root
和
Match Address $ip
PermitRootLogin {yes|without-password}
AllowUsers *
两者都被完全忽略。“ ssh”组中的普通用户仍然只能登录。
这是一个简单的场景,用户登录名限制为pubkey,而根用户登录名限制为pubkey和某些ip。怎么解决?
您尚未发布全部内容sshd_config
,因此很难重现这种情况,但这似乎可行:
# Main config prohibits all logins
PermitRootLogin no
AllowUsers root
# Permit root logins from a specific address
Match Address 192.168.1.20
PermitRootLogin yes
# Allow logins to anyone in "ssh" group.
Match Group ssh
AllowUsers *
另一个解决方案是:
在您的以下内容sshd_config
:
AllowGroups ssh
PermitRootLogin without-password
成为root
该ssh
组的成员。
usermod -a -G ssh root
向其添加/root/.ssh/authorized_keys
具有受限制的源地址的公钥,如下所示:
from=192.168.1.20 ssh-rsa ...
这将为您提供所需的东西:
ssh
可以登录。root
只能从authorized_keys
文件中的特定IP地址登录。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句