> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/server-administration/client-authentication/auth-pam.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 20.13. PAM 驗證 \#

### 20.13. PAM 驗證 [#](#auth-pam) <a href="#auth-pam" id="auth-pam"></a>

這種驗證方法的運作方式與 `password` 類似，差別在於它使用 PAM（Pluggable Authentication Modules，可插拔驗證模組）作為驗證機制。 預設的 PAM 服務名稱為 `postgresql`。 PAM 只用來驗證使用者名稱／密碼組合，並可選擇性地驗證 所連線的遠端主機名稱或 IP 位址。因此，使用者必須已經 存在於資料庫中，才能使用 PAM 進行驗證。關於 PAM 的更多 資訊，請閱讀 [Linux-PAM 頁面](https://www.kernel.org/pub/linux/libs/pam/)。

PAM 支援下列設定選項：

`pamservice` : PAM 服務名稱。

`pam_use_hostname` : 決定透過 `PAM_RHOST` 項目提供給 PAM 模組的是遠端 IP 位址 還是主機名稱。預設使用 IP 位址。將此選項設為 1，即可改用 解析後的主機名稱。主機名稱解析可能導致登入延遲。（大多數 PAM 設定不會使用這項資訊，因此只有在某個 PAM 設定是特地為了 使用這項資訊而建立時，才需要考慮這項設定。）

#### 注意

如果 PAM 設定為讀取 `/etc/shadow`，驗證將會失敗， 因為 PostgreSQL 伺服器是由非 root 使用者啟動的。 不過，當 PAM 設定為使用 LDAP 或其他驗證方法時， 就不會有這個問題。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/auth-pam.html)（原文版本：18.6；核對日期：2026-10-10）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/server-administration/client-authentication/auth-pam.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
