PAM(3)
β¨ PAM(3) β the Linux-PAM girlies' guide β¨
ok so bestie, welcome to PAM, aka Pluggable Authentication Modules Library β the friend group of libraries that handles all the authentication tasks for applications (services) on the system. literally the backstage crew of your whole login experience π
It gives you a stable general interface (Application Programming Interface β API, you know her) that privilege-granting programs (think login(1) and su(1), the classics) defer to when they need to do standard authentication tasks. no cap, they just hand the whole vibe check over to PAM π«Ά
πΈ SYNOPSIS πΈ
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <security/pam_ext.h>
three headers, that's it, that's the whole entry fee π
π¦ DESCRIPTION π¦
π Initialization and Cleanup π
The pam_start(3) function creates the PAM context and kicks off the PAM transaction. it's the first of the PAM functions an app needs to call β like, the opening act, the main character entrance, periodt.
The transaction state lives entirely inside the structure identified by this handle, so yes bestie, you can absolutely have multiple transactions in parallel, slay. BUT β and this is the important part π β you can NOT reuse the same handle for different transactions. a new one is needed for every new context. one handle, one transaction, that's the rule π
The pam_end(3) function terminates the PAM transaction and is the last function an app should call in the PAM context. Upon return, the handle pamh is no longer valid and all memory associated with it will be invalid. it can be called at any time to terminate a PAM transaction β anytime, she's flexible like that β¨
π₯ Authentication π₯
The pam_authenticate(3) function is used to authenticate the user. the user is required to provide an authentication token, which depends on the authentication service β usually this is a password, but it could also be a finger print π
The pam_setcred(3) function manages the user's credentials. that's it, that's the job, and she does it well π
π§ Account Management π§
The pam_acct_mgmt(3) function is used to determine if the user's account is valid. it checks for authentication token and account expiration and verifies access restrictions. it's typically called after the user has been authenticated β like the vibe check that comes AFTER the password check π
π Password Management π
The pam_chauthtok(3) function is used to change the authentication token for a given user β either on request or because the token has expired. expired token? we don't know her, we're changing it π
π Session Management π
The pam_open_session(3) function sets up a user session for a previously successfully authenticated user. the session should later be terminated with a call to pam_close_session(3) β open then close, balance, harmony, the way nature intended π¦
π« Conversation π«
The PAM library uses an application-defined callback to allow direct communication between a loaded module and the application. this callback is specified by the struct pam_conv passed to pam_start(3) at the start of the transaction. see pam_conv(3) for details β she has her own whole page, iykyk πΈ
β Data Objects β
The pam_set_item(3) and pam_get_item(3) functions allow applications and PAM service modules to set and retrieve PAM information. setting and getting, the original duo π
The pam_get_user(3) function is the preferred method to obtain the username. not me telling you there are other ways β no, just use this one, it's iconic π
The pam_set_data(3) and pam_get_data(3) functions allow PAM service modules to set and retrieve free-form data from one invocation to another. free-form, unbothered, living her best life π
π«Ά Environment and Error Management π«Ά
The pam_putenv(3), pam_getenv(3) and pam_getenvlist(3) functions are for maintaining a set of private environment variables. private, exclusive, invite-only π
The pam_strerror(3) function returns a pointer to a string describing the given PAM error code. so when something goes wrong (and bestie, something always goes wrong), this is who you ask π
π RETURN VALUES π
ok these are the return codes PAM knows about. there are a LOT of them, so buckle up, we're going through every single one, no skipping, no summarizing, that's not the vibe we're on today π«‘
PAM_ABORTβ Critical error, immediate abort. like, drop everything and run πPAM_ACCT_EXPIREDβ User account has expired. bye bestie πPAM_AUTHINFO_UNAVAILβ Authentication service cannot retrieve authentication info.PAM_AUTHTOK_DISABLE_AGINGβ Authentication token aging disabled.PAM_AUTHTOK_ERRβ Authentication token manipulation error.PAM_AUTHTOK_EXPIREDβ Authentication token expired.PAM_AUTHTOK_LOCK_BUSYβ Authentication token lock busy.PAM_AUTHTOK_RECOVERY_ERRβ Authentication information cannot be recovered.PAM_AUTH_ERRβ Authentication failure. the classic, the icon, the one everyone fears πPAM_BUF_ERRβ Memory buffer error.PAM_CONV_ERRβ Conversation failure. the conversation did NOT go well β¨PAM_CRED_ERRβ Failure setting user credentials.PAM_CRED_EXPIREDβ User credentials expired.PAM_CRED_INSUFFICIENTβ Insufficient credentials to access authentication data.PAM_CRED_UNAVAILβ Authentication service cannot retrieve user credentials.PAM_IGNOREβ The return value should be ignored by PAM dispatch. literally just look away πPAM_MAXTRIESβ Have exhausted maximum number of retries for service. you tried, you tried again, that's enough π«ΆPAM_MODULE_UNKNOWNβ Module is unknown. who is she? we don't know her πΈPAM_NEW_AUTHTOK_REQDβ Authentication token is no longer valid; new one required.PAM_NO_MODULE_DATAβ No module specific data is present.PAM_OPEN_ERRβ Failed to load module.PAM_PERM_DENIEDβ Permission denied. nope, not for you bestie π«PAM_SERVICE_ERRβ Error in service module.PAM_SESSION_ERRβ Cannot make/remove an entry for the specified session.PAM_SUCCESSβ Success. πβ¨π THE return code. this is the one you're manifesting.PAM_SYMBOL_ERRβ Symbol not found.PAM_SYSTEM_ERRβ System error.PAM_TRY_AGAINβ Failed preliminary check by password service.PAM_USER_UNKNOWNβ User not known to the underlying authentication module. stranger danger π
π§ SEE ALSO π§
the whole friend group, all tagged, all linked, all iconic π
pam_acct_mgmt(3), pam_authenticate(3), pam_chauthtok(3), pam_close_session(3), pam_conv(3), pam_end(3), pam_get_data(3), pam_getenv(3), pam_getenvlist(3), pam_get_item(3), pam_get_user(3), pam_open_session(3), pam_putenv(3), pam_set_data(3), pam_set_item(3), pam_setcred(3), pam_start(3), pam_strerror(3)
β οΈ NOTES β οΈ
The libpam interfaces are only thread-safe if each thread within the multithreaded application uses its own PAM handle. read that again. one handle per thread. no sharing, no borrowing, no "just this once" π€
and that's the whole page bestie, you ate π β¨
this has been Linux-PAM, dated 07/08/2026, the PAM(3) manual page β go forth and authenticate responsibly π«Άπ
π¦ where this page comes from
- fedora 44: pam-devel 1.7.2-2.fc44 Β· BSD-3-Clause AND GPL-2.0-or-later
- fedora 44: pam-devel 1.7.2-2.fc44 Β· BSD-3-Clause AND GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms