Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Node.js cannot listen: EACCES permission denied on a port

ErrorError: listen EACCES: permission denied 0.0.0.0:80

Short answer

On Linux, ports below 1024 are privileged. A normal user cannot bind to them, so listen fails with EACCES. Keep the app on a high port behind a reverse proxy, or give the process only the CAP_NET_BIND_SERVICE capability. Do not run the whole app as root.

  • Applies to Node.js 22, Node.js 24, Ubuntu 24.04, systemd 255
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the address in the error. A port under 1024 points to the first cause; a file path points to the second.

    node server.js 2>&1 | grep EACCES
    id -u
  2. 2Match what you see, then jump to its fix

    1. 1listen EACCES: permission denied 0.0.0.0:80 or :443Port below 1024 without the right to bind itFix
    2. 2You started node from a plain shell as a normal user and no capability is setThe capability must be on the process, not just wantedFix
    3. 3listen EACCES: permission denied /run/my-app.sock (a path, not a port)A Unix socket path the user cannot useFix

What does the error look like?

  • Error: listen EACCES: permission denied 0.0.0.0:80
  • code: 'EACCES', syscall: 'listen'

Cause 1 of 3

Port below 1024 without the right to bind it

1Check

Linux calls ports below 1024 privileged. Binding to one needs the CAP_NET_BIND_SERVICE capability, which a normal user does not have; EACCES is the documented error for it.

id -u
grep -n "listen" server.js

2Fix

Best: run the app on a high port such as 3000 and let nginx or another proxy own 80 and 443. If you must bind low ports directly, grant the capability to the service instead of using root.

# systemd unit
[Service]
User=app
AmbientCapabilities=CAP_NET_BIND_SERVICE

3Verify

Restart the service and request the port.

sudo systemctl daemon-reload && sudo systemctl restart my-app
curl -I http://127.0.0.1:80

Confirmed by man7.org

Did this fix it?

Cause 2 of 3

The capability must be on the process, not just wanted

1Check

CAP_NET_BIND_SERVICE is what allows binding to ports below 1024. Without it on the process or the binary, the kernel refuses. Check what the Node.js binary has.

getcap $(readlink -f $(which node))

2Fix

For a quick local test, add the capability to the Node.js binary. This applies to every script run with that binary, so avoid it on shared servers.

sudo setcap cap_net_bind_service=+ep $(readlink -f $(which node))

3Verify

Start the app on the low port as the normal user.

node server.js

Confirmed by man7.org

Did this fix it?

Cause 3 of 3

A Unix socket path the user cannot use

1Check

For an IPC path, the server owner and permissions decide who can connect. The Node.js net docs note that a server started as root may leave a path other users cannot reach.

ls -l /run/my-app.sock

2Fix

Start the server as the same user that should own it, or set readableAll and writableAll when listening, so all users can reach it.

server.listen({ path: '/run/my-app.sock', readableAll: true, writableAll: true });

3Verify

A client can connect through the socket.

curl --unix-socket /run/my-app.sock http://localhost/

Confirmed by nodejs.org

Did this fix it?

How do I stop it coming back?

  • Terminate TLS and own ports 80 and 443 in a reverse proxy; keep Node.js on a high port.
  • Never run the full Node.js app as root just to bind a port.
  • Put capability settings in the unit file so they survive redeploys.
  • Print the port from config at start-up so a wrong value is obvious.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.