Fortunately this can be easily done with openSSH. Just edit the /etc/ssh/sshd_config file and add the desired directives shown below. You don’t need them all, just use what suits you needs.
openSSH provides 4 directives, AllowUsers, AllowGroups, DenyUsers and DenyGroups
AllowUsers buddy john doeOnly users buddy, john and doe will be able to log in via ssh.
AllowGroups sysadmin bkpadminOnly users within groups sysadmin and bkpadmin will be able to log in via ssh.
DenyUsers rambo tinaThis is the opposite of AllowUsers. All users except for rambo and tina will be able to log in via ssh.
DenyGroups hr payrollThis is the opposite of AllowGroups. All groups except for hr and payroll will be able to log in via ssh.