This course is using an outdated version of the technology and is now considered to be Legacy content. It will be removed from our catalog on June 28, 2024. Please be sure to complete your course and finish any remaining labs before that date. We recommend moving to version 9.2, which is the latest version currently available.
In this exercise, you will make changes to PAM configuration files manually and with system utilities, and explore the effects this has on the system.
Outcomes
You should be able to:
Back up the PAM configuration.
Make changes to PAM, ensuring that a root shell is open at all times to recover from errors.
Manually add and configure a PAM module to the configuration.
Explore when PAM configuration changes take effect.
Make a second change with authconfig and show what effect that has on the manual changes.
Restore the original PAM configuration.
Confirm that the workstation and serverc machines are started.
Log in to workstation as student using student as the password.
On workstation, run lab pam-modify setup to verify that the environment is ready.
This script also creates the operator1 and developer1 users, and the operators group.
[student@workstation ~]$lab pam-modify setup
Before modifying your PAM configuration, open an extra root shell on serverc to recover from errors.
Back up the PAM files.
Open a new terminal on workstation and log in to serverc as student.
No password is required.
[student@workstation ~]$ssh student@serverc[student@serverc ~]$
Use the sudo -i command to switch identity to the root user.
Use student as the password.
[student@serverc ~]$sudo -i[sudo] password for student:student[root@serverc ~]#
Leave this terminal open at all times to recover from potential errors.
From another terminal, log in to serverc as student.
No password is required.
[student@workstation ~]$ssh student@serverc[student@serverc ~]$
Use the sudo -i command to switch identity to the root user.
Use student as the password.
[student@serverc ~]$sudo -i[sudo] password for student:student[root@serverc ~]#
Use the authconfig --savebackup=/root/authconfigbackup command to back up the PAM configuration into the /root/authconfigbackup/ directory.
[root@serverc ~]#authconfig --savebackup=/root/authconfigbackup[root@serverc ~]#
Configure the pam_time module so that users can only log in using SSH or the console between 6 p.m. and 11 p.m. on any given day.
This restriction does not apply to root and student; they must be able to log in at any time.
The authconfig command cannot configure the pam_time module.
Therefore you need to manually perform this configuration.
You need to add the rule for the pam_time module in the /etc/pam.d/system-auth and /etc/pam.d/password-auth files, because most of the PAM-enabled applications include those files, specifically sshd and login (for the console access).
If you directly modify these files, however, a subsequent call to authconfig may overwrite them.
Confirm that /etc/pam.d/system-auth and /etc/pam.d/password-auth are links to the /etc/pam.d/system-auth-ac and /etc/pam.d/password-auth-ac files.
[root@serverc ~]#ls -l /etc/pam.d/system-authlrwxrwxrwx. 1 root root 14Mar 22 15:11/etc/pam.d/system-auth -> system-auth-ac[root@serverc ~]#ls -l /etc/pam.d/password-authlrwxrwxrwx. 1 root root 16Mar 22 15:11/etc/pam.d/password-auth -> password-auth-ac
These two *-ac files (ac for AuthConfig) are in fact the ones updated by the authconfig command.
Copy system-auth-ac and password-auth-ac files to system-auth-local and password-auth-local.
This two local files will contain your modifications.
[root@serverc ~]#cd /etc/pam.d[root@serverc pam.d]#cp system-auth-ac system-auth-local[root@serverc pam.d]#cp password-auth-ac password-auth-local
Recreate the links to point to your new local files.
[root@serverc pam.d]#rm system-auth password-authrm: remove symbolic link ‘system-auth’?yrm: remove symbolic link ‘password-auth’?y[root@serverc pam.d]#ln -s system-auth-local system-auth[root@serverc pam.d]#ln -s password-auth-local password-auth[root@serverc pam.d]#ls -l system-auth password-authlrwxrwxrwx. 1 root root 19Jul 12 10:25password-auth -> password-auth-local lrwxrwxrwx. 1 root root 17Jul 12 10:25system-auth -> system-auth-local
You are now ready to add a new rule for the pam_time module.
Review the manual page for the pam_time module.
[root@serverc pam.d]#man pam_time...output omitted...
This module is only valid for the account management group.
Edit your system-auth-local and password-auth-local files and add the new rule before the other account rules.
[root@serverc pam.d]#vim system-auth-local...output omitted... auth requisite pam_succeed_if.so uid >= 1000 quiet_success auth required pam_deny.soaccount required pam_time.soaccount required pam_unix.so account sufficient pam_localuser.so ...output omitted...[root@serverc pam.d]#vim password-auth-local...output omitted... auth requisite pam_succeed_if.so uid >= 1000 quiet_success auth required pam_deny.soaccount required pam_time.soaccount required pam_unix.so account sufficient pam_localuser.so ...output omitted...
Edit the /etc/security/time.conf configuration file to set the time restriction.
Add the following line at the end to allow the access between 6 p.m. and 11 p.m.
This restriction does not apply to root and student.
The configuration requires 24-hour format.
[root@serverc pam.d]#vim /etc/security/time.conf...output omitted... sshd|login;*;!root&student;Al1800-2300
Consult the time.conf(5) manual page if you need more details.
Try to log in to localhost as operator1 using redhat as the password.
This should fail.
[root@serverc pam.d]#ssh operator1@localhostThe authenticity of host 'localhost (::1)' can't be established. ECDSA key fingerprint is SHA256:BMdnasLF5CBGg42Dx77nuXodXdI9dKoEBQGFK5O0HRI. ECDSA key fingerprint is MD5:9e:a8:ec:0c:86:d2:70:34:ef:5a:94:15:6d:48:73:db. Are you sure you want to continue connecting (yes/no)?yesoperator1@localhost's password:redhatAuthentication failed.[root@serverc pam.d]#
If you are able to log in as operator1, use the date command to verify the system time and review the /etc/security/time.conf file.
You might need to adjust the time range in that file to trigger the rule.
Try to log in to localhost as student using student as the password.
This should succeed.
Log out when done.
[root@serverc pam.d]#ssh student@localhoststudent@localhost's password:student[student@serverc ~]$logout[root@serverc pam.d]#
Comment out or remove the added line to the /etc/security/time.conf file.
The remainder of this exercise may not work as expected otherwise.
[root@serverc pam.d]#vim /etc/security/time.conf...output omitted...#sshd|login;*;!root&student;Al1800-2300
Switch your PAM configuration from the legacy authentication methods to SSSD.
Install SSSD and use the authconfig --enablesssdauth --update command to enable SSSD for authentication.
[root@serverc pam.d]#yum install sssd...output omitted... Is this ok [y/d/N]:y...output omitted... Complete![root@serverc pam.d]#authconfig --enablesssdauth --update[root@serverc pam.d]#
Because you have redirected the system-auth and password-auth links to your custom files, system-auth-local and password-auth-local, instead of the default system-auth-ac and password-auth-ac files, the update you have just made is not taken into account.
Remember that authconfig only modifies the *-ac files.
Confirm that authconfig has added the rules for pam_sss to the system-auth-ac and password-auth-ac files but not to your custom system-auth-local and password-auth-local files.
[root@serverc pam.d]#grep pam_sss.so system-auth-ac password-auth-acsystem-auth-ac:auth sufficient pam_sss.so forward_pass system-auth-ac:account [default=bad success=ok user_unknown=ignore] pam_sss.so system-auth-ac:password sufficient pam_sss.so use_authtok system-auth-ac:session optional pam_sss.so password-auth-ac:auth sufficient pam_sss.so forward_pass password-auth-ac:account [default=bad success=ok user_unknown=ignore] pam_sss.so password-auth-ac:password sufficient pam_sss.so use_authtok password-auth-ac:session optional pam_sss.so[root@serverc pam.d]#grep pam_sss.so \>system-auth-local password-auth-local[root@serverc pam.d]#
In this exercise, because you want to manually modify the PAM configuration but also keep using the authconfig command, you need to include the *-ac files in your *-local files.
Edit the system-auth-local file, only keep your custom rules, and include the system-auth-ac file.
Your file should look similar to the following:
[root@serverc pam.d]#vim system-auth-localauth include system-auth-ac account required pam_time.so account include system-auth-ac password include system-auth-ac session include system-auth-ac
In the same way, edit your password-auth-local file.
It should look similar to the following:
[root@serverc pam.d]#vim password-auth-localauth include password-auth-ac account required pam_time.so account include password-auth-ac password include password-auth-ac session include password-auth-ac
Use the *-local files for your manual modifications.
authconfig uses the *-ac files for its own modifications.
Restrict access to your system as follows:
Members of the operators group can only log in if they attempt access from workstation (172.25.250.254).
The root and student users can log in from anywhere.
Other users are not allowed to log in.
Use the authconfig command to enable the pam_access module and configure the /etc/security/access.conf file.
Locate the authconfig option that enables pam_access.
[root@serverc pam.d]#authconfig --help | grep access--enablepamaccess check access.conf during account authorization --disablepamaccess do not check access.conf during account authorization
Enable the pam_access module and verify your work.
[root@serverc pam.d]#authconfig --enablepamaccess --update[root@serverc pam.d]#grep pam_access.so \>system-auth-ac password-auth-acsystem-auth-ac:account required pam_access.so password-auth-ac:account required pam_access.so
Edit the /etc/security/access.conf configuration file to apply the restrictions.
[root@serverc pam.d]#vim /etc/security/access.conf...output omitted... +:root student: ALL +:(operators):172.25.250.254 -:ALL:ALL
Verify your configuration by trying to log in from workstation to serverc as developer1 using redhat as the password.
This should fail because the developer1 user does not belong to the operators group.
[root@serverc pam.d]#logout[student@serverc ~]$logout[student@workstation ~]$ssh developer1@servercAuthentication failed.[student@workstation ~]$
Try to log in as operator1.
If prompted, use redhat as the password.
The connection succeeds because operator1 is a member of the operators group and the connection is originating from workstation.
Log out and log in again as student when done.
[student@workstation ~]$ssh operator1@servercLast failed login:Wed Jul 18 07:08:29 EDT 2018from localhost on ssh:notty There was 1 failed login attempt since the last successful login.[operator1@serverc ~]$logout[student@workstation ~]$ssh student@servercLast login:Wed Jul 18 07:08:48 2018from localhost[student@serverc ~]$
Review the log of the sshd daemon and locate the denied access.
[student@serverc ~]$journalctl -u sshd...output omitted...Jul 12 13:15:25serverc.lab.example.com sshd[4136]:pam_access(sshd:account):access denied for user 'developer1'from 'workstation.lab.example.com'Jul 12 13:15:25serverc.lab.example.com sshd[4136]: fatal: Access denied for user developer1 by PAM account configuration [preauth] ...output omitted...
Use the authconfig command to restore your PAM configuration.
Use the sudo -i command to switch identity to the root user.
Use student as the password.
[student@serverc ~]$sudo -i[sudo] password for student:student[root@serverc ~]#
Restore the PAM configuration from the /root/authconfigbackup/ directory.
[root@serverc ~]#authconfig --restorebackup=/root/authconfigbackup[root@serverc ~]#
Review the contents of the /etc/pam.d/ directory.
[root@serverc ~]#ls -l /etc/pam.d/...output omitted... lrwxrwxrwx. 1 root root 19Jul 12 11:26password-auth -> password-auth-local -rw-r--r--. 1 root root 1033Jul 12 13:30password-auth-ac -rw-r--r--. 1 root root 178Jul 12 13:14password-auth-local ...output omitted... lrwxrwxrwx. 1 root root 17Jul 12 11:26system-auth -> system-auth-local -rw-r--r--. 1 root root 1031Jul 12 13:30system-auth-ac -rw-r--r--. 1 root root 170Jul 12 12:23system-auth-local ...output omitted...
Notice that the restore process did not remove the links to your *-local files.
It only restored the *-ac files and preserved your custom modifications.