Category: Access and AuthenticationUpdated 2026-10-18

AllowUsers

AllowUsers is an OpenSSH server (sshd_config) directive that restricts SSH login to accounts whose names match a list of patterns, optionally limited to particular source hosts with the USER@HOST form. If it is set, every account not listed is refused; if it is absent, it imposes no restriction. DenyUsers is checked first, and AllowGroups and DenyGroups do the same job for groups.

What AllowUsers does and how patterns work

The sshd_config manual says that if AllowUsers is specified, login is allowed only for user names that match one of the patterns, and that by default login is allowed for all users. Entries are separated by spaces. Only names are valid: a numerical user ID is not recognized. Patterns follow the rules in ssh_config(5), where * matches any number of characters, ? exactly one, and a leading ! negates an entry, though a negated match never produces a positive result by itself.

The form USER@HOST checks the user name and the connecting host separately, so a user can be allowed only from certain origins. The manual adds that the host part may contain addresses in CIDR address/masklen format. The group counterparts are AllowGroups, which matches a primary or supplementary group name, and the deny forms DenyUsers and DenyGroups.

Repeating the keyword on several lines does not replace the earlier list. In the OpenSSH source, each line appends to it.

A minimal safe configuration and how to test it

The classic lockout is listing the wrong name, or forgetting your own. List every account that must log in over SSH, including automation, then verify from a second terminal while your current session stays open:

# /etc/ssh/sshd_config
AllowUsers admin deploy@192.0.2.0/24

sudo sshd -t
sudo sshd -T | grep -i '^allowusers '
sudo systemctl reload ssh     # sshd on some distributions

Here admin may connect from anywhere, while deploy only from that network. sshd -t checks the file, and sshd -T prints the effective configuration, optionally with -C to apply Match blocks, as the sshd(8) manual explains. Then try to log in as an account that is not listed. It must be refused, and the server log should show a line in the form "User NAME from ADDRESS not allowed because not listed in AllowUsers" (taken from the OpenSSH source). Finally, confirm that your own login and every service account still work before you close the old session. Keep the provider console as a way back.

Precedence, interactions and common mistakes

The manual states that AllowUsers is not consulted for users matched by DenyUsers, and likewise for the group pair. The source shows the full order of checks: DenyUsers, then AllowUsers, then DenyGroups, then AllowGroups. A login must pass every list that is configured. If you set both AllowUsers deploy and AllowGroups ssh-users, deploy must also belong to ssh-users.

Where it fits in SSH hardening

An allow-list shrinks the attack surface: a stolen key or a guessed password for an account that is not listed is rejected before it helps anyone. It also stops a newly created system account, or one added by a package, from becoming an SSH entry point by accident. For teams, AllowGroups is often easier to maintain than a list of names, since adding someone becomes a group change rather than a config edit.

AllowUsers works best next to PasswordAuthentication set to no, PermitRootLogin set to no and narrow sudo rules, following least privilege. In larger setups, funnel logins through a bastion host and restrict by source network at the firewall too. The rollout order is in our SSH hardening guide, the privilege side in users, sudo and least privilege, and the network side in the Linux firewall guide. Primary sources: the sshd_config manual and the OpenSSH auth.c source.

Related terms: sshd_config, PermitRootLogin, Least privilege, Bastion host, authorized_keys.

Frequently asked questions

What does AllowUsers do in sshd_config?

It allows SSH login only for user names that match one of its patterns. If the directive is not set, login is allowed for all users, subject to the other settings.

What is the difference between AllowUsers and AllowGroups?

AllowUsers matches user names, while AllowGroups matches a primary or supplementary group name. Groups are usually easier for teams, because access changes by editing group membership instead of the config file.

Which wins if a user is in both AllowUsers and DenyUsers?

DenyUsers wins. The manual says AllowUsers is not consulted for users matched by DenyUsers, and the source checks DenyUsers first.

How do I allow a user only from one IP address or network?

Use the USER@HOST form, for example deploy@192.0.2.0/24. The user and the host are checked separately, and the host part may be an address in CIDR notation.

Why can root or a service account no longer log in after I set AllowUsers?

Once AllowUsers is set, every account not listed is refused, including root and automation users. Add the accounts that need SSH, then check the result with sshd -T and a test login.

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