Ubuntu – How to set up an FTP user with access to web root using vsftpd

Apache2ftpservervsftpd

How do I set up an FTP user with access to web root using vsftpd?

I am currently setting up a website and I am trying to learn more about web servers on the way. I used shared hosting providers before, but this time I'd like to set up the server from scratch with a VPS. I installed a LAMP stack already and installed WordPress. Everything works so far except for updating WordPress automatically since it is asking for FTP access.

Therefore I installed vsftpd by following this tutorial. This also works accordingly.

The problem is that in the tutorial the FTP user has it's dedicated files directory (/home/ftp_user/ftp/files), but I need to give the user access to the web root (/var/www/html/site) for WordPress performing the update.

I tried having the local_root point to /var/www/html

and I tried setting up a symlink like this

ln -s /var/www/html /home/ftp_user/ftp/files

but both ways do not work. When I try to connect, it says

vsftpd: refusing to run with writable root inside chroot()

What is the proper way to achieve this? Or would it be better to not use the /var/www/html location at all?

Best Answer

FTP does not follow symlinks for good reasons. Instead, you should use a bind-mount.

# Create mount directory below ftp/files
mkdir /home/ftp_user/ftp/files/www

# Mount
mount -o bind /var/www/html /home/ftp_user/ftp/files/www

Try if it works.

To make it permanent add this to /etc/fstab:

/var/www/html /home/ftp_user/ftp/files/www none defaults,bind 0 0

Be aware that unlike a symlink, if you delete the www-folder you will remove all the files in /var/www/html too.