Configure user vsftpd in a specific directory

March 12, 2015 5.6k views
Apache Linux Commands Ubuntu

Hello friends!

I am beginner and installed the LAMP package in Ubuntu, but I can not make the following settings:

I created a user named "oregon" and want to access SFTP with it, but I need that he has as root directory** /var/www** because I will publish your site files in /var/www/html. Also not want him to see above directories and preference.

Already asked for help in supporting and read the tutorials, but could not solve :(

Every moment is a different problem, I can never complete this setting, please help me.

5 Answers

Are you using FTP or SFTP? As far as I know, vsftpd does not support SFTP.

You could bind the user folder to the /html.
1. To keep it tidy create a folder in the user's folder:
mkdir -p /home/{user}/www/html
where {user} should be changed to the user name. Also create the html folder in /var/www if it doesn't exist yet.

2. Then to mount it:
mount --bind /var/www/html /home/{user}/www/html

You're basically binding these folders, as the docs states: “--bind Remount a subtree somewhere else (so that its contents are available in both places)”

3. You'll still need to make it permanent, so:
sh -c 'echo "/var/www/html /home/{user}/www/html none defaults,bind 0 0" >> /etc/fstab'

which is the equivalent to add the bind command to the /etc/fstab, so it's executed every time your system boots.

@Woet I am a novice, do not know what I'm doing. What do I need at the moment is: access the FTP or SFTP with the user created. As you would with handles sshd SFTP?

@redraenhys Thank you, I will perform this procedure when I was at home.

  • Quick unrelated tip: You don't seem fully familiar with managing your own server, thus it's a nice idea to keep a record with everything you installed and configured (even the links of tutorials you followed are helpful). This way if in the future something goes wrong or you decide to do some change it'll save a lot of time you'd otherwise spend scratching your head and asking yourself "err, what exactly did I do when I setup this thing 729723 months ago?".

    That's what I do and it has been doing wonders for me.



I tested your tip and now can not send files to the server, the only problem is that no page or directory is accessible, to make the browser via access displays the following message:


You don't have permission to access / on this server.

Apache/2.4.7 (Ubuntu) Server at Port 80

You can't or you can? It sounds like you can. Anyway, it seems that you got a permissions problem now. You can check it with:

ls -l /var/www

You can read more about them here: FilePermissions
I believe that apache (www-data) isn't the owner of your html directory, and your user isn't in this group either, thus you need to allow "Others" to read and execute or no one will be able to access the site. The classic permissions for sites are 755 for folders and 644 for files.

P.s.: Accidentally posted this as an answer instead of a reply to your new answer. Dang.

Have another answer? Share your knowledge.