1

I have an Ubuntu 16.04 web server. It only hosts one site using Nginx. I want to keep things very simple, and store the index.html file and the whole website in /var/www/html.

I need to be able to FTP files into /var/www/html. I have installed vsftp. I've created a user with the useradd command, which I'll call exampleuser. I then used this command:

sudo usermod -d /var/www/html exampleuser

... thinking that this would make the home directory of exampleuser to be the default directory when I log in by FTP.

However, when I attempt to log in by FTP, I get a "login error". I've checked and double checked my username and password and I'm certain they're correct, so I'm guessing it's a permissions issue (also because my experience is that most of the time in Linux when things don't work as hoped it's because of permissions). Though it's possible it could be a vsftpd configurations issue.

I think I've set the html directory in /var/www to have the right access:

/var/www$ ls -la
total 12
drwxr-xr-x  3 root          root          4096 Nov 10 06:54 .
drwxr-xr-x 14 root          root          4096 Nov 10 06:54 ..
drwxr-xr-x  2 exampleuser exampleuser 4096 Nov 10 08:04 html

What do I need to do so that I can ftp to /var/www/html?

7
  • Not a security expert but why not have sudo rm /var/www and then have sampleuser create /var/www and /var/www/html? Also does the directory have to be in /var which is a system folder? Nov 11, 2016 at 17:07
  • What is the log in error ?
    – Panther
    Nov 11, 2016 at 17:10
  • @bodhi.zazen, my client says "Login failed." The vsftp log says "FAIL LOGIN: Client".
    – Questioner
    Nov 11, 2016 at 17:18
  • What error is in your logs ? Simply stating it is not working and guessing at the problem is not going to make much progress. See also help.ubuntu.com/community/… as your directories do not have proper permissions.
    – Panther
    Nov 11, 2016 at 17:18
  • 1
    I am not sure it is a permissions problem. You can try making /var and /var/www rwx by your other user, although that has it's own security problems.
    – Panther
    Nov 11, 2016 at 17:36

1 Answer 1

0

Yes it is a permission error take a look on this tutorial:

FTP is generally more secure when users are restricted to a specific directory.vsftpd accomplishes this with chroot jails. When chroot is enabled for local users, they are restricted to their home directory by default. However, because of the way vsftpd secures the directory, it must not be writable by the user. This is fine for a new user who should only connect via FTP, but an existing user may need to write to their home folder if they also shell access.

In this example, rather than removing write privileges from the home directory, we're will create an ftp directory to serve as the chroot and a writable files directory to hold the actual files.

Create the ftp folder, set its ownership, and be sure to remove write permissions with the following commands:

sudo mkdir /home/sammy/ftp
sudo chown nobody:nogroup /home/sammy/ftp
sudo chmod a-w /home/sammy/ftp

If you try to connect to the ftp and the user can write the folder then it wont connect, you need to add to the root folder the owner nobody:nogroup, so if you want to keep things simple just point your server to the folder where the user can write in your case:

sudo usermod -d /var/www exampleuser

This is because you want to write on HTML folder

sudo chown nobody:nogroup /var/www
sudo chmod a-w /var/www

Modify your server conf file and point to the new location which will be HTML this solution helps a lot if you really want to use Very Safe FTP

Not the answer you're looking for? Browse other questions tagged .