How can one allow or deny an ssh login for a specific user(s) or group(s) on an sshd server?
(I realize SE has similar questions, but not I could find any that address this specific point. All others I found appear to conflate other scenarios.)
How can one allow or deny an ssh login for a specific user(s) or group(s) on an sshd server?
(I realize SE has similar questions, but not I could find any that address this specific point. All others I found appear to conflate other scenarios.)
Update the sshd config
To deny a user ssh login, add this to the end of your sshd config file (
/etc/ssh/sshd_config
in Linux/Unix/BSD):DenyUsers theusername
For groups:
DenyGroups thegroupname
Restart the sshd service
Then restart the
sshd
service. The following works on Ubuntu 18.04:systemctl restart sshd
More details
One can add a space-separated list of user or group names, respectively.
The
AllowUsers
andAllowGroups
directives do the opposite.Excerpt from the sshd_config man page:
Another way to do it is by using access.conf.
First, you need to enable pam_access in /etc/pam.d/sshd by adding the following line:
required pam_access.so
Then you can edit /etc/security/access.conf, and remove access to the required user(s)/group(s) by adding the following line for each one:
-:<user or group>:ALL