我试图将相同的sshd
设置应用于多个用户。
根据手册,Match User
看起来就像一个AND
:
引入一个条件块。如果满足
Match
行上的所有条件,则以下行上的关键字将覆盖配置文件全局部分中设置的关键字
如何声明“对于任何这些用户.”,因此在本例中允许bob
、joe
和phil
使用SSH作为代理,但不允许登录:
Match User bob, User joe, User phil
PasswordAuthentication yes
AllowTCPForwarding yes
ForceCommand /bin/echo 'We talked about this guys. No SSH for you!'
发布于 2017-02-12 18:43:24
没有亲自做过这件事,我只能按照手册上说的去做:
来自sshd_config
手册:
匹配模式可以由单个条目或逗号分隔的列表组成,并且可以使用
ssh_config(5)
的patterns部分中描述的通配符和否定运算符。
这意味着你应该能说出
Match User bob,joe,phil
PasswordAuthentication yes
AllowTCPForwarding yes
ForceCommand /bin/echo 'We talked about this guys. No SSH for you!'
也请参阅信息安全论坛上的答案:https://security.stackexchange.com/a/18038
发布于 2017-02-12 18:31:32
对组而不是用户使用Match指令。然后将用户添加到该组中。
Match Group users_with_no_ssh
PasswordAuthentication yes
AllowTCPForwarding yes
ForceCommand /bin/echo 'We talked about this guys. No SSH for you!'
发布于 2019-01-29 21:53:33
我不确定ForceCommand是否能很好地与SFTP合作。另外,也许最好在日志中看到'DenyUsers‘这个词。总之,我使用这个(嗯,也许使用Group会更好):
sshd_config
# support, ansible & backup only from specific IP
Match User ansible,backup,support Address *,!176.x.x.x
DenyUsers ansible,backup,support
Match User backup
AllowTcpForwarding yes
AllowAgentForwarding yes
PermitListen 127.0.0.1:2223
AcceptEnv RESTIC_REPOSITORY RESTIC_PASSWORD
测试配置
# sshd -T -C addr=176.x.x.x,user=backup | egrep '^((deny|allow)users|permitlisten|acceptenv)'
denyusers root
acceptenv RESTIC_REPOSITORY
acceptenv RESTIC_PASSWORD
permitlisten 127.0.0.1:2223
# sshd -T -C addr=8.8.4.4,user=backup | egrep '^((deny|allow)users|permitlisten|acceptenv)'
denyusers ansible,backup,support
acceptenv RESTIC_REPOSITORY
acceptenv RESTIC_PASSWORD
permitlisten 127.0.0.1:2223
真实世界测试
Jan 29 16:50:12 mx1 sshd[71309]: Connection from 199.x.x.x port 21042 on 199.x.x.x port 2222 rdomain "0"
Jan 29 16:50:13 mx1 sshd[71309]: User support from 199.x.x.x not allowed because listed in DenyUsers
Jan 29 16:50:13 mx1 sshd[71309]: Connection closed by invalid user support 199.x.x.x port 21042 [preauth]
https://unix.stackexchange.com/questions/344444
复制相似问题