A PAM exec module that validates SSH logins against NetBird peer identity.
NetBird's built-in SSH server does not use OpenSSH, it runs its own embedded Go SSH server and spawns sessions via the system login binary, which means auth goes through /etc/pam.d/login, not /etc/pam.d/sshd.
This module hooks into that flow to validate that the connecting peer's NetBird identity matches the requested Unix username.
Non-NetBird logins are passed through untouched without any API calls.
- A user connects via
netbird sshor the NetBird SSH client - NetBird's SSH server calls
login -f <username> -h <peer_ip>, which triggers the/etc/pam.d/loginPAM stack - This binary reads
PAM_RHOST(source IP) andPAM_USER(requested username) - If the IP is outside the configured NetBird subnet, it exits successfully and lets the rest of the PAM stack proceed normally
- Otherwise it reads
/etc/netbird-pam/config.envand queries the NetBird API to find the peer and its associated user - It derives a Unix username from the user's email (
foo.bar@example.com→foo-bar) - If that matches
PAM_USER, access is granted, otherwise it is denied
Create /etc/netbird-pam/config.env (root-readable only):
NETBIRD_PAM_TOKEN=your-api-token
NETBIRD_PAM_API_URL=https://api.netbird.io
NETBIRD_PAM_IP_PREFIX=100.sudo mkdir -p /etc/netbird-pam
sudo chmod 600 /etc/netbird-pam/config.env
sudo chown -R root:root /etc/netbird-pam| Variable | Description |
|---|---|
NETBIRD_PAM_TOKEN |
NetBird API token |
NETBIRD_PAM_API_URL |
API base URL, e.g. https://api.netbird.io |
NETBIRD_PAM_IP_PREFIX |
IP prefix to match NetBird peers, e.g. 100. |
CGO_ENABLED=0 go build -o netbird-pam .Cross-compilation:
# amd64
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o netbird-pam-x86_64 .
# arm64 (e.g. Raspberry Pi)
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o netbird-pam-aarch64 .sudo cp netbird-pam-x86_64 /usr/local/lib/netbird-pam
sudo chown root:root /usr/local/lib/netbird-pam
sudo chmod 755 /usr/local/lib/netbird-pamAdd to /etc/pam.d/login before @include common-auth:
auth required pam_exec.so /usr/local/lib/netbird-pam
Logs are written to syslog under the netbird-pam tag and appear in journalctl -t netbird-pam.
Pre-built binaries for linux/amd64 and linux/arm64 are available on the Releases page.