pgpass is a PostgreSQL password file that stores connection credentials for automatic login. It lets client tools supply a username and password for specific host, port, database and user combinations without prompting, so file permissions and local exposure of the secret are the main control concerns.
What Pgpass Is Used For
pgpass is a PostgreSQL password file that enables client tools to authenticate non-interactively against specific host, port, database, and user combinations. Its purpose is convenience, but its security value is narrow and highly dependent on local file protection.
Because it stores reusable credentials in cleartext form, pgpass is best understood as a secret-handling mechanism rather than a database feature. The practical question is whether the file can be read only by the intended account and whether the stored secret is limited to the smallest useful scope.
How Pgpass Is Structured
The file supports a simple matching model: if a connection attempt matches the listed host and database details, the client can supply the saved password automatically. That makes it useful for scripts, scheduled jobs, migration tooling, and other repeatable database tasks where interactive prompting would break automation.
The structure also means one file can become a concentration point for multiple credentials. If an attacker or an unintended local user can read it, they may gain access to several database paths at once, especially if the same account owns multiple entries with broad reuse.
Why Pgpass Becomes a Security Concern
Pgpass is risky when people treat it as a harmless convenience file instead of sensitive authentication material. The main exposure is local, not network-based: filesystem permissions, user profile security, backups, container mounts, and endpoint compromise all become relevant because the secret is stored where the client can read it.
It also creates a durability problem. A password placed in pgpass tends to live longer than an interactive login session, so any secret that should have been short-lived may persist across hosts, automation jobs, or developer workstations. That is why secret scope and file placement matter as much as the password itself.
How to Use Pgpass Safely in Practice
Use pgpass only for accounts that truly need non-interactive database access, and keep each entry as specific as practical. The narrower the host, database, and user match, the less damage a stolen file can do. Limit operating system read access to the owning account and treat copied home directories, shared build agents, and container images as potential leakage paths.
When possible, prefer stronger secret handling patterns for higher-value environments, such as centrally managed secret storage, short-lived credentials, or tightly controlled service accounts. Pgpass is acceptable as an operational convenience only when the surrounding host security is already strong enough to protect the stored password.
Risk and Threat Considerations
Pgpass concentrates authentication secrets in a location that is often easy to overlook during host hardening, backup, and incident response. If the file is exposed, the attacker does not need to defeat PostgreSQL itself, they only need the password and a reachable database endpoint.
Failure mechanism: Weak file permissions, stolen endpoint access, or copied profiles can reveal multiple database credentials at once, turning a convenience file into a credential theft path.
Impact: An exposed pgpass file can enable unauthorized database access, data exfiltration, privilege abuse, or lateral movement into additional systems that trust the same credentials.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Pgpass stores reusable passwords, so authenticator lifecycle control applies directly. |
| AC-6 — Least Privilege | Pgpass security depends on limiting which local users can read the file and which database rights the password grants. | |
| CM-6 — Configuration Settings | The file's security hinges on correct local permission and system configuration. | |
| Recommendation — Manage stored database passwords as authenticators, and restrict their creation, distribution, rotation, and storage. Apply least privilege to both file access and database permissions for any account using pgpass. Set and enforce secure filesystem permissions for pgpass and verify them during system build and review. | ||
| CIS Controls v8 | CIS-5 — Account Management | Pgpass is an account access mechanism, so account and secret governance directly affect its risk. |
| Recommendation — Inventory accounts that rely on pgpass and remove unnecessary stored credentials. | ||
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Pgpass is a password file, so leakage of the stored secret is the core failure mode. |
| Recommendation — Treat pgpass as secret material and prevent exposure through filesystem, backup, and image leakage. | ||
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 29, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org