/etc/pam.d/sshd./etc/pam.conf, and the configuration directory for PAM is /etc/pam.d/. If the /etc/pam.d/ directory exists, the /etc/pam.conf file is ignored.type, control, module-path, and module-arguments.type field are as follows:type Value | Description |
Account management (Account) | Provides account verification services, such as checking whether user passwords are expired and whether access to requested services is allowed. |
Authentication (Auth) | Authenticate users and set user certificates. Authentication can be performed by using passwords, one-time passwords, hardware authentication, and other methods. |
Password management (Password) | Update the authentication mechanism, commonly used to manage the creation, change, and deletion of user passwords. For example, set password complexity, expiration time, and other attributes. |
Session management (Session) | Perform operations when a user logs in and logs out, such as recording the user's login time, configuring the environment, setting resource limits, and allocating file system space. |
- character, the PAM library will not log to the system log if the module cannot be loaded because it is missing from the system.control field are as follows:control Value | Description |
required | The module must be successfully executed; otherwise, authentication fails. After a failure, subsequent modules continue to be executed and failure information is returned. |
requisite | The module must be successfully executed; otherwise, authentication fails immediately and subsequent modules are not executed. |
sufficient | If the module is successfully executed, authentication succeeds immediately and subsequent modules are not executed. If the module fails, authentication does not fail immediately; instead, subsequent modules continue to be executed. |
optional | The module execution result does not affect the authentication result unless it is the only module. |
include | Insert the content of another PAM configuration file directly into the current configuration file. |
substack | Pause the current stack and start executing modules in the referenced file. After all modules in the referenced file are executed, PAM resumes executing the next module in the current file. |
[value1=action1 value2=action2 ...]/lib64/security/ directory. You can also use custom modules via an absolute path.man pam_unix.pam_listfile.so module to allow or deny specific users access to a service. For example, the following configuration can be used to prevent the root user from logging in via SSH./etc/pam.d/sshd file and add the following rule on the first line to prevent the root user from logging in via SSH. This rule uses the pam_listfile.so module to check whether the login username exists in the deny list. The control flag is set to required, which means authentication can continue only when the module check passes (that is, the user is not in the deny list):auth required pam_listfile.so item=user sense=deny file=/etc/ssh/deniedusers onerr=fail
/etc/ssh/deniedusers and add the usernames to be denied SSH login:sudo vim /etc/ssh/deniedusers
sudo chmod 600 /etc/ssh/deniedusers
item=user: Specifies that the check target is user.sense=deny: Specifies the action to take if the corresponding user is found in the file specified by file. If the user is not found, the opposite action is taken.file=/etc/ssh/deniedusers: Specifies the file that contains one user per line.onerr=fail: Specifies the action to take when an error occurs.pam_listfile.so module, run man pam_listfile to check the man page.pam_limits.so module to set limits on system resources. For example, the following configurations can be used to limit the number of user login sessions./etc/pam.d/login and /etc/pam.d/sshd files, and add a rule to enable the pam_limits.so module:session required pam_limits.so
/etc/security/limits.conf file. By default, the pam_limits.so module reads the /etc/security/limits.conf configuration file and the /etc/security/limits.d/*.conf files. Add the following lines to limit user user1 and members of group group1 to a maximum of 3 concurrent login sessions:user1 - maxlogins 3@group1 - maxlogins 3
user1 has multiple login sessions, the following prompt will be displayed:There were too many logins for 'user1'.
OPENCLOUDOS.COM.Host Name | Private IP Address | Role |
KDC | 192.168.160.161 | Master KDC |
Client | 192.168.160.165 | Kerberos Client |
/etc/hosts file on both hosts to ensure that the host names can be resolved:192.168.160.161 KDC192.168.160.165 Client
dnf install krb5-server krb5-workstation krb5-libs
/etc/krb5.conf. Configure the Kerberos authentication service in this file, and synchronize the file to all hosts that use Kerberos.[libdefaults]default_realm = OPENCLOUDOS.COM[realms]OPENCLOUDOS.COM = {kdc = 192.168.160.161admin_server = 192.168.160.161}
/var/kerberos/krb5kdc/kdc.conf. Modify the configuration information of the Kerberos realm on the KDC server.[realms]OPENCLOUDOS.COM = {acl_file = /var/kerberos/krb5kdc/kadm5.acldict_file = /usr/share/dict/wordsdefault_principal_flags = +preauthadmin_keytab = /var/kerberos/krb5kdc/kadm5.keytabsupported_enctypes = aes256-cts:normal aes128-cts:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal}
/var/kerberos/krb5kdc/kadm5.acl. This file controls administrative permissions for the Kerberos database and grants the admin principal full access permission.*/admin@OPENCLOUDOS.COM *
*/admin is an account form in Kerberos and indicates accounts belonging to the OPENCLOUDOS.COM realm. The * sign in the end indicates that accounts in the */admin form have all permissions.kdb5_util create -s -r OPENCLOUDOS.COM
-s indicates creating a secure Kerberos database, and -r specifies the Kerberos realm of the database. After the database is created, new files will be generated in the /var/kerberos/krb5kdc/ directory.kadmin.local -q "addprinc root/admin"
kadmin.local -q "addprinc krbtest/admin"
listprincs command to view all users:kadmin.localkadmin.local: listprincs
sudo systemctl start krb5kdcsudo systemctl start kadminsudo systemctl enable krb5kdcsudo systemctl enable kadmin
/var/log/krb5kdc.log and /var/log/kadmind.log.firewall-cmd --add-service=kerberos --permanentfirewall-cmd --add-service=kadmin --permanentfirewall-cmd --add-service=kpasswd --permanentfirewall-cmd --reload
dnf install krb5-workstation krb5-libs
krb5.conf file in the KDC.kinit command to verify that the KDC issues tickets. The tickets are stored in the credential cache file, and this command can also be used to test the Kerberos authentication service:kinit krbtest/admin
klist
kdestroy
idm.example.com domain:sssctl access-report idm.example.com
sssctl user-checks -a acct -s sshd example.user
sssctl domain-list
sssctl domain-status idm.example.com
sssctl config-check
/etc/sssd/sssd.conf file:[domain/your-domain-name]cache_credentials = true
[pam]offline_credentials_expiration = 3
offline_credentials_expiration defaults to 0, which means no limit./etc/sssd/sssd.conf file:[domain/your-domain-name]id_provider = ldapldap_uri = _srv_chpass_provider = ldapldap_chpass_dns_service_name = ldap
dns_discovery_domain option.ldap_dns_service_name option.lookup_family_order option.access_provider to simple mode to allow or deny access based on user names or groups:[domain/your-domain-name]access_provider = simplesimple_allow_users = user1, user2simple_allow_groups = group1
dnf -y install openldap-clients sssd sssd-ldap oddjob-mkhomedir
authselect select sssd with-mkhomedir
/etc/openldap/certs directory:cp core-dirsrv.ca.pem /etc/openldap/certs
/etc/openldap/ldap.conf file:URI ldap://ldap-server.example.com/BASE dc=example,dc=com
TLS_CACERT option in the /etc/openldap/ldap.conf file:TLS_CACERT /etc/openldap/certs/core-dirsrv.ca.pem
ldap_uri and ldap_search_base parameters in the /etc/sssd/sssd.conf file:[domain/default]ldap_uri = ldap://ldap-server.example.com/ldap_search_base = dc=example,dc=com
/etc/sssd/sssd.conf file:cache_credentials = Trueldap_tls_cacert = /etc/openldap/certs/core-dirsrv.ca.pemldap_tls_reqcert = hard
/etc/sssd/sssd.conf file:chmod 600 /etc/sssd/sssd.conf
systemctl restart sssd oddjobdsystemctl enable sssd oddjobd
id command to specify an LDAP user to search for user data from the LDAP server:id <ldap_user>
피드백