Categories
Uncategorized

Allow Chrooted User Access To Outside Directories

To allow access to a directory by a chrooted linux user (which lies outside the user’s dir tree) use “mount –bind sourceDirPath targetDirPath”

Mounting a directory means creating a link to the contents of the directory anywhere on the volume or even another volume. For example, if you have a D:/ and a C:/, one can create a link to the D:/ in the C:/ and access the contents of the D:/ as if it were a folder within the C:/

Using the bind –mount however, replicates one directory structure within the other (and not just created a link). Any changes made in one directory get reflected in the other directory immediately.

One use case: You are working on a project and want to give access to two different directories to a chrooted linux user. Furthermore, neither of the two directories are within the home directory of the chrooted user. This would not possible since the home directory of the chrooted user does not contain either of the dirs (that is the whole point of chrooting a user!).

Using “mount –bind” the root user can allow the chrooted user access to any number of dirs which are outside the home dir of this user.

To allow access to the outside dir, the root user must first create an empty dir under the chrooted user’s home dir with the same name and then bind the empty dir to the outside dir.

For example, assume the chrooted user’s home dir is /var/www/chr_dir and the root user wants the chrooted user to have access to /var/www/someDir.

sudo mkdir /var/www/chr_dir/someDir
mount --bind /var/www/someDir /var/www/chr_dir/someDir

Now when the chrooted user logs into his account (via FTP or SSH or otherwise); he will see someDir as one the directories with all the same contents as they are under /var/www/someDir.

To remove the user’s access to the directory, use the ‘umount’ command:

sudo umount /var/www/chr_dir/someDir

This will “unmount” the directory from the user’s home directory and the user will not have access to the contents of the outside directory anymore. Do note that the dir ‘someDir’ will still appear in the user’s account. Only its contents will get removed. To remove the actual directory itself, remove it using the “rm” command.

Source: https://askubuntu.com/questions/780406/is-mount-bind-dir1-dir2-an-alternative-for-hard-links-for-directories

 1,755 total views,  3 views today

Categories
Uncategorized

Add Node Packages Globally

When you install a new nodejs package, it will get installed in your home directory by default. This is usally /home/$USER where $USER is ‘centos’ on a Centos machine . In order to run a module GLOBALLY on your machine, you will need to install the package globally and set the NODE_PATH environment variable after the installation.

For example, to install ‘puppeteer’ globally run this command:

sudo npm install -g --save puppeteer --unsafe-perm=true --

This will install the ‘puppeteer’ package to /usr/lib/node_modules/puppeteer/

However, if you try to run a puppeteer script from anywhere on your server, you will get an error saying:

internal/modules/cjs/loader.js:895
throw err;  ^
Error: Cannot find module 'puppeteer'

To make puppeteer available globally on your machine simply add the path to the node_modules to your server’s environment variables like so:

For linux machines, you will need to add the line given (for each distro) to your bash profile. Do ‘sudo vi ~/.bash_profile ‘ ; add the line given below; save the file; then logout and login to the SSH environment for the changes to take effect:

  • Centos: export NODE_PATH=/usr/lib/node_modules
  • Ubuntu: export NODE_PATH=/usr/local/lib/node_modules
  • Windows 7/8*: Add to path C:\Users\{USERNAME}\AppData\Roaming\npm\node_modules
  • Windows 10*: Add to path %AppData%\npm\node_modules


*On windows system, you can add to your path by following these steps:

  • Open the Start Search, type in “env”, and choose “Edit the system environment variables”
  • Click the “Environment Variables…” button.
  • Under the “System Variables” section (the lower half), find the row with “Path” in the first column, and click edit.
  • The “Edit environment variable” UI will appear. Here, you can click “New” and type in the new path you want to add. From this screen you can also edit or reorder them.
  • Dismiss all of the dialogs by choosing “OK”. Your changes are saved!
  • Restart the machine (or at least the apps that require the path) in order for the changes to take effect.

 1,452 total views,  2 views today