Skip to content

Instantly share code, notes, and snippets.

@981746
Forked from vibegui/nodejs-ubuntu-bind-port-80.md
Last active August 29, 2015 14:10
Show Gist options
  • Save 981746/25e746235beaaee5c79e to your computer and use it in GitHub Desktop.
Save 981746/25e746235beaaee5c79e to your computer and use it in GitHub Desktop.

Revisions

  1. @Gadr Gadr revised this gist Jan 6, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions nodejs-ubuntu-bind-port-80.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,10 @@
    *Only do this if you understand the consequences: all node programs will be able to bind on ports < 1024*

    sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node

    Important: your node location may vary. Use `which node` to find it, or use it directly in the command:

    sudo setcap 'cap_net_bind_service=+ep' `which node`

    ### Explanation

  2. @Gadr Gadr revised this gist Aug 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nodejs-ubuntu-bind-port-80.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # How to: Allow Node to bind to port 80 without sudo
    ## How to: Allow Node to bind to port 80 without sudo

    ### TL;DR

  3. @Gadr Gadr revised this gist Aug 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nodejs-ubuntu-bind-port-80.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@

    In UNIX-like systems, non-root users are unable to bind to ports lower than 1024.

    This is a nuisance while proxying adresses on port 80. Tipically, you end up `sudo`ing all apps that must bind to such ports.
    This is a nuisance when proxying adresses on port 80. Tipically, you end up `sudo`ing all apps that must bind to such ports.

    However, since kernel 2.6.24, you can use the `setcap` command to set specific capabilities to a program.

  4. @Gadr Gadr created this gist Aug 30, 2013.
    31 changes: 31 additions & 0 deletions nodejs-ubuntu-bind-port-80.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # How to: Allow Node to bind to port 80 without sudo

    ### TL;DR

    *Only do this if you understand the consequences: all node programs will be able to bind on ports < 1024*

    sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node

    ### Explanation

    In UNIX-like systems, non-root users are unable to bind to ports lower than 1024.

    This is a nuisance while proxying adresses on port 80. Tipically, you end up `sudo`ing all apps that must bind to such ports.

    However, since kernel 2.6.24, you can use the `setcap` command to set specific capabilities to a program.

    To enable **all node programs to bind on any port lower than 1024**, issue the following command:

    sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node

    *Voilà*! You can now bind to port 80 without `sudo`ing.

    If your `node` binary isn't on this path, find it with `whereis node` and substitute `/usr/local/bin/node` for wherever it is.

    ### Important Caveat

    `setcap` functions *per-program*. Therefore, if you update your node version you will probably need to run this command again.

    ----------------

    source: http://stackoverflow.com/a/414258