Skip to main content

Restrict Login To Members Of Specific Group(s)

(2026-11-25)

Create a custom PAM profile:

New file: /usr/share/pam-configs/access

Name: Access control via /etc/security/access.conf
Default: yes
Priority: 128
Account-Type: Additional
Account:
        required                        pam_access.so

Append the below to the bottom of /etc/security/access.conf:

+ : root : ALL
+ : (allowed_group) : ALL
+ : (sudo) : ALL
- : ALL : ALL
+ : root : ALL
+ : (allowed_group) : ALL
+ : (sudo) : ALL
+ : cron crond : 0
- : ALL : ALL

...or specify those user accounts specifically instead of the cron line.

Activate the profile:

sudo pam-auth-update --package

Testing:

  • it is advised to keep an already-logged in session running while testing, so you don't inadvertently lock yourself and everyone else out.