Skip to content

unable to create listener: Error listen tcp4 0.0.0.0:443: bind: permission denied – Fix in Ubuntu

I was trying to use kubectl and port forward the service ports to local but Ubuntu doesn’t allow to bind to 443.

$ kubectl port-forward --address 0.0.0.0 service/traefik 8000:8000 8080:8080 443:4443 -n default
Forwarding from 0.0.0.0:8000 -> 8000
Forwarding from 0.0.0.0:8080 -> 8080
Unable to listen on port 443: Listeners failed to create with the following errors: [unable to create listener: Error listen tcp4 0.0.0.0:443: bind: permission denied]

To fix this we can use setcap and allow the program to bind to ports.

sudo setcap CAP_NET_BIND_SERVICE=+eip $(which kubectl)
$ kubectl port-forward --address 0.0.0.0 service/traefik 8000:8000 8080:8080 443:4443 -n default
Forwarding from 0.0.0.0:8000 -> 8000
Forwarding from 0.0.0.0:8080 -> 8080
Forwarding from 0.0.0.0:443 -> 4443

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.