How to give ftp users access to directories outside their home folder in linux


You are using a webserver like apache2 or lighttpd to host websites under the /var/www directory, and letting your linux users upload and edit the files in their home folder via ftp.

Each user use their own domain, and maybe you have set up virtualhosts in apache2.

That is a convenient way to host multiple sites for multiple people, but, you may have a problem if you are using the traditional symlink between the two folders; users home directory, and the webservers default root directory.

Say you have 2 users, with 2 different websites:

User Jen:

  • Home folder:  /home/Jen
  • Documentroot, virtualhost: /var/www/

User Alex:

  • Home folder: /home/Alex
  • Documentroot, virtualhost: /var/www/

And you are using vsftpd, with the setting chroot_local_user=YES so that users are limited to their own home folder.

You could then create a symlink ln -s between /home/Alex/ and /var/www/ so Alex could manage his website from his home directory. that would work, but not via ftp, since it does not follow symlinks outside Alex’s home folder.


This took me some time to figure out, but the solution is actually simple.

Instead of using the traditional symlink, you can in linux mount two folders like this:

Make sure the directories /home/Alex/ and /var/www/ exists (create them with mkdir)

Then mount the two folders with

mount –bind  /home/Alex/ /var/www/

Now Alex should be able to update his website files in his home folder, via ftp, and at the same time, apache can serve his website from the default /var/www directory (ubuntu default).

A workaround

This is a simpler workaround, a solution, but not to the specific problem of giving ftp users access.

Instead of symlinking or mounting directories between apaches www folder and users home folder, you could just point the documentroot of the apache virtualhosts to /home/Alex/ or /home/Jen/ instead.

But then you scatter your webfiles around the server, and make running backups harder.

comments powered by Disqus