Step #1: Create Allow User Lists
Create a text file called /usr/local/etc/kdm.deny or /usr/local/etc/gdm.deny, enter:
# vi /usr/local/etc/gdm.allow
Add each username on a separate line. In this example, deny access to user tom, jerry, spike, tyke, butch etc:
tom
jerry
spike
tyke
butch
Save and close the file. You can to use the same file for kdm using ln command:
# ln -s /usr/local/etc/gdm.allow /usr/local/etc/kdm.allow
Any user name present in these file will no longer be able to login via GDM (GNOME) or KDM (KDE) systems. But, those users can still login using ssh or use su and/or sudo commands.
Step #2: Restrict GDM User Login
Edit /etc/pam.d/gdm, enter:
# vi /etc/pam.d/gdm
Append / modify line as follows:
auth required pam_listfile.so onerr=fail item=user sense=allow file=/usr/local/etc/gdm.allow
Save and close the file.
Step #3: Restrict KDM User Login
Edit /etc/pam.d/kdm, enter:
# vi /etc/pam.d/kdm
Append / modify line as follows:
auth required pam_listfile.so onerr=fail item=user sense=allow file=/usr/local/etc/gdm.allow
Save and close the file.