1

Is it possible to use logical operators in AllowGroups in sshd_config? The thing I want to achieve is to permit user to access server only when it belongs to two groups. ChatGPT gave me this answer, but I'm not convinced to it... I didn't find any other useful information, even in documentation.

Many thanks for answer.

1 Answer 1

1

The answer by ChatGPT is pure nonsense - this tool is meant to produce works that emulate human texts, but you should not treat it on the same level as Google.

sshd_config allows patterns in the AllowGroups directive, which are defined as:

A pattern consists of zero or more non-whitespace characters, *' (a wildcard that matches zero or more characters), or ?' (a wildcard that matches exactly one character).

A pattern-list is a comma-separated list of patterns. Patterns within pattern-lists may be negated by preceding them with an exclamation mark (`!').

Specifically, the | and & operators are not included.

For your problem, you might be able to achieve the restriction to the two groups by using the negation operator, such as:

DenyGroups !group1,!group2

So anyone who is either not in group1 or not in group2 is denied login.

5
  • Yes, I didn't even think that ChatGPT's answer is best option. ! will not work for me, because I need to match both groups, not one of them. Anyway, your post answers my question. Thank you for clarification!
    – sp33dy
    Jan 3, 2023 at 19:47
  • 1
    Logic laws says that "not ( (not group1) or (not group2) )" is the same as "group1 and group2". See De Morgan's laws.
    – harrymc
    Jan 3, 2023 at 19:51
  • Sure, but DenyGroups !group1,!group2 is not the same as DenyGroups !(!group1,!group2) and I can't do latter. Or am I wrong?
    – sp33dy
    Jan 3, 2023 at 20:05
  • Sorry to say, but you're wrong. Take some examples and you'll see.
    – harrymc
    Jan 3, 2023 at 20:38
  • Sure I will, thank you.
    – sp33dy
    Jan 3, 2023 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .