Alternatively, you can create a /var/lib/google-authenticator directory, run restorecon -rv on it, and configure your PAM module to use that location. The SELinux rules are pre-defined for that location:
Does the parent directory have the right permissions?
# ls -Zld /var/lib/google-authenticator
drwxrwxrwt. 2 root root system_u:object_r:container_file_t:s0:c2 12 Aug 29 2022 /var/lib/google-authenticator
It is OK to run sudo chmod 1777 /var/lib/google-authenticator so that any user can (re)create their OTP key at any time (but another non-root user will not be able to change the key).
The line in your PAM config’s auth stack might look something like the following.
Edit: Correction, when you run /usr/bin/google-authenticator (not PAM’s pam_google_authenticator.so), it will generate the files under /var/lib/google-authenticator and set restrictive permissions on them.[1]
Assuming you supply -s /var/lib/google-authenticator/${USER} as a parameter. ↩︎