Applicable to:
- Plesk for Linux
Question
How to add Node.js engine for users with /bin/bash (chrooted) shell?
Answer
Note: Article must be double checked and Plesk database dump made before any actions.
Note: npm will not be able to add packages globally via npm install -g
, because root permissions are required to write to the /usr/lib/node_modules
.
Warning: Mounting /proc to chroot could potentially allow users to escape chroot.
-
Connect to the server via SSH;
-
Download the
update_chroot.sh
script from the following article: How to add new programs to a chrooted shell environment template?; -
Add the Node.js executable files and required coreutils:
# ./update_chroot.sh --add nodejs js node dirname env readlink sed uname
Note: Not all of mentioned Node.js executables are present on some Linux distributions.
-
Add the npm package manager and globally installed JS modules:
# cp -a /usr/bin/npm /var/www/vhosts/chroot/usr/bin
# cp -a /usr/lib/node_modules/ /var/www/vhosts/chroot/usr/lib/ -
Apply the template to all subscriptions:
# ./update_chroot.sh --apply all
-
Mount
/proc
to the subscription's directory, so it could be used by Node.js and NPM:# mkdir /var/www/vhosts/example.com/proc
# mount --rbind /proc /var/www/vhosts/example.com/proc -
Verify, that the Node.js engine works in the chroot, by opening a shell as a user with /bin/bash (chrooted) access:
# sudo -iu chrooted_user
$ node -v
v8.9.3
Note: npm will not be able to add packages globally via npm install -g
, because root permissions are required to write to the /usr/lib/node_modules
.
Warning: Mounting /proc to chroot could potentially allow users to escape chroot.
Comments
0 comments
Please sign in to leave a comment.