SSH允许Windows AD组(带特殊字符)
我已成功加入我的linux到Windows域,现在域中的每个人都可以使用ssh登录到服务器。
但我们只想允许一组中的某些用户登录。
当前两组的示例:
#it_admin Domain Admin
你可以用两种方式做到这一点。 一种是让SSH配置过滤,另一种是使用pam_access
。
使用SSH配置
到/etc/ssh/sshd_config
,添加一个AllowGroups
行:
AllowGroups Domain Admin
从联机帮助页 :
AllowGroups This keyword can be followed by a list of group name patterns, separated by spaces. If specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns.
此处的Domain Admin
与Domain Admin
不匹配组名,但是两个单独的组Domain
和Admin
。 你必须使用Domain*Admin
和*it_admin
,因为它们都没有 (空格)和(
#
)通常是Linux组中的有效字符。 为了更安全,使用?
而不是*
: Domain?Admin
和?it_admin
,因此通配符只允许一个字符。 您还可以添加基于模式的DenyGroups部分。 请参阅man ssh_config
的PATTERNS
部分。
使用pam_access
在表格的/etc/security/access.conf
中添加以下行:
- : ALL EXCEPT (Domain) (Admin) : ALL
该文件中有大量注释记录了如何使用它。 man pam_access
非常man pam_access
,所以大部分信息都来自那些评论。 pam_access
更强大,因为它也可以控制非SSH登录(TTY,GUI等)。 例如,此特定行应拒绝任何没有Domain
或Admin
作为组的用户登录(除非其他行允许)。
这两种方法都非常灵活,我不知道利弊,所以没有建议。