PAM_SETCRED(3)

✨ PAM_SETCRED(3) ✨

okay bestie, we're in the Linux-PAM Manual today and this one's about credentials β€” literally the stuff that makes you you on a system πŸ’…


πŸŽ€ NAME πŸŽ€

pam_setcred β€” establish / delete user credentials


🌸 SYNOPSIS 🌸

#include <security/pam_appl.h>

int pam_setcred(pam_handle_t *pamh, int flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

So the pam_setcred function is the one you call to establish, maintain and delete the credentials of a user, fr fr. Like, here's the timeline bestie: the user gets authenticated, then you set their credentials, and then a session is opened for them (with pam_open_session(3)). And when the session is closed (with pam_close_session(3)), the credentials get deleted after that. Order matters, no cap 🫢

And what even is a credential? Great question. A credential is something the user possesses β€” like some property of theirs, e.g. a Kerberos ticket, or a supplementary group membership, that makes up the uniqueness of a given user. Iconic user-specific vibes ✨

On a Linux system the user's UID and GID's are credentials too. BUT (and this is the plot twist πŸ’€) it's been decided that these properties β€” along with the default supplementary groups the user is a member of β€” are credentials that should be set directly by the application and not by PAM. So those ones should be established by the application prior to a call to this function. Like, initgroups(2) (or equivalent) should already have been performed by then. Do not skip this step bestie πŸ™ˆ

Now the valid flags β€” any one of which may be logically OR'd with PAM_SILENT β€” are:

  • PAM_ESTABLISH_CRED β€” Initialize the credentials for the user.
  • PAM_DELETE_CRED β€” Delete the user's credentials.
  • PAM_REINITIALIZE_CRED β€” Fully reinitialize the user's credentials.
  • PAM_REFRESH_CRED β€” Extend the lifetime of the existing credentials.

πŸ’œ RETURN VALUES πŸ’œ

  • PAM_BUF_ERR β€” Memory buffer error 😭
  • PAM_CRED_ERR β€” Failed to set user credentials.
  • PAM_CRED_EXPIRED β€” User credentials are expired (the tragedy).
  • PAM_CRED_UNAVAIL β€” Failed to retrieve user credentials.
  • PAM_SUCCESS β€” Data was successful stored. slay ✨
  • PAM_SYSTEM_ERR β€” A NULL pointer was submitted as PAM handle, the function was called by a module, or another system error occurred. messy πŸ’€
  • PAM_USER_UNKNOWN β€” User is not known to an authentication module.

🌈 SEE ALSO 🌈

pam_authenticate(3), pam_open_session(3), pam_close_session(3), pam_strerror(3)


heads up bestie: credentials get set after auth and before the session opens, deleted after the session closes, and the UID/GID/group stuff is the application's job, not PAM's. iykyk πŸ’…

okay that's the whole page and honestly? ate. this was Linux-PAM, dated 07/08/2026 β€” go forth and set those creds, main character πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from