AllowGroups
AllowGroups is an OpenSSH server (sshd_config) directive that allows SSH login only for users whose primary or supplementary group matches a listed group name. If it is set, everyone else is refused with the log line "none of user's groups are listed in AllowGroups". Access is then managed by group membership instead of by editing the config file.
What AllowGroups does and how group matching works
The sshd_config manual says that if AllowGroups is specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns, and that by default login is allowed for all groups. Entries are separated by spaces and follow the pattern rules in ssh_config(5), so * and ? work. Only group names are valid: a numerical group ID is not recognized.
The keyword may appear several times, and each instance appends to the list. The manual also states that AllowGroups is not consulted for groups matched by DenyGroups. A typical setup creates one group and lists it:
sudo groupadd sshusers
sudo usermod -aG sshusers deploy
echo 'AllowGroups sshusers' | sudo tee /etc/ssh/sshd_config.d/20-allowgroups.conf
It is the group counterpart of AllowUsers. Teams usually prefer it, because access is granted with usermod instead of by editing the config. Add your own account to the group before you reload sshd.
The error "none of user's groups are listed in AllowGroups"
When AllowGroups is set and the account is in none of the listed groups, sshd refuses the login before it looks at the key or password. The client only sees a generic Permission denied (publickey,password), so the reason is in the server log. We ran OpenSSH 9.6p1 on Ubuntu 24.04.5 with AllowGroups sshusers, and a user outside the group produced this line:
User bob from 127.0.0.1 not allowed because none of user's groups are listed in AllowGroups
Find it with sudo journalctl -u ssh --since "10 min ago" | grep "not allowed" on Debian and Ubuntu (the unit is called sshd on Fedora-family systems), or in /var/log/auth.log where rsyslog writes it. The usual causes:
- the user was never added to the group, or was added to a group with a similar name;
- the group name in the file has a typo, or the group does not exist;
- the groups come from a directory service such as LDAP or SSSD and the lookup fails, which
idwill show.
How to fix it without locking yourself out
Check what the system says, not what you believe you set:
getent group sshusers
id bob
sudo sshd -T | grep -i '^allowgroups '
The first command shows the group and its members, the second shows the groups the account actually has, and the third prints the effective list. If the group is missing from the account, add it:
sudo usermod -aG sshusers bob
Keep the -a: without it, usermod replaces the user's supplementary groups. In our test the user could log in on the next attempt with no reload, because sshd reads the group list at each login. Sessions that are already open keep the groups they started with. When you change the directive itself:
- Keep one session open and have your provider console ready.
- Add your own account to the group first.
- Run
sudo sshd -t, then reload sshd. - Log in from a new terminal before you close the old one.
If you are already locked out, use the console and follow the SSH lockout recovery guide.
Interactions with AllowUsers, DenyGroups and drop-in files
A login must pass every list that is configured. In our test, with AllowGroups sshusers and AllowUsers alice together, a member of sshusers who was not alice was refused with "not allowed because not listed in AllowUsers". The OpenSSH source checks DenyUsers, then AllowUsers, then DenyGroups, then AllowGroups. A user in a group named by DenyGroups is refused with "not allowed because a group is listed in DenyGroups", even if the same group is also in AllowGroups.
Two traps matter in practice. First, every AllowGroups line appends, across files too: with sshusers in a drop-in and wheel in the main file, sshd -T printed both, so a forgotten line can admit a group you did not intend. Second, sshd -t accepts a group that does not exist, so a typo passes the check and then matches nobody.
The lists apply to every account, root and automation users included, so decide who belongs to the group before you set it. For the surrounding baseline read PermitRootLogin, MaxAuthTries and the SSH hardening guide.
Related terms: sshd_config, AllowUsers, PermitRootLogin, Least privilege, MaxAuthTries.
Frequently asked questions
What does AllowGroups do in sshd_config?
It allows SSH login only for users whose primary or supplementary group matches one of the listed names. If it is not set, login is not restricted by group.
What does "not allowed because none of user's groups are listed in AllowGroups" mean?
AllowGroups is set and the account belongs to none of the listed groups, so sshd refused the login. Check the account with id and the list with sshd -T, then add the user to the group.
Do I need to restart sshd after adding a user to the allowed group?
No. In our test the user could log in on the next attempt after usermod -aG, with no reload. Only changes to the sshd configuration need a reload.
Does AllowGroups match the primary group or only supplementary groups?
Both. The manual says it matches the primary group or the supplementary group list, and a user whose primary group was the allowed group logged in successfully in our test.
Does sshd -t catch a misspelled group name in AllowGroups?
No. sshd -t only checks syntax, so a name of a group that does not exist passes and simply matches nobody. Check the real groups with getent group and read the result with sshd -T.
Want to see where your own server stands?
Run the free, read-only server check, or open the Security Lab and watch the detect, contain, recover, verify loop in action.
Get your free server checkOpen the Security Lab