FTP & SFTP – Beginners guide to Digital Ocean

Ernest Marcinko Hosting, Tutorials 1 Comment

So far we have a running web server with a working database, but we don't have FTP access.

SFTP

However we do have SFTP access. How so? The root and the demo user are valid SFTP accounts as well. So if you have an SFTP client like Filezilla or Notepad++, you can use the demo account to upload your files.

I recommend using Filezilla, it can support 1-10 parallel uploads, which can make things more comfortable.

FTP

For FTP access we need to install the vsftpd package:

sudo apt-get install vsftpd

After this is done, you need to edit the configuration in the /etc/vsftpd.conf file, so let's open that up:

sudo nano /etc/vsftpd.conf

You need to search for each of these options inside that file (with CTRL + W in nano editor) and change them to these values:

anonymous_enable=NO
local_umask=022
chroot_local_user=YES

Then search for these lines and remove the hashtag (#) before them:

write_enable=YES
local_enable=YES

Finally, add the following line to the end of the file:

force_dot_files=YES

This will ensure, that the .htaccess files are visible and editable in your FTP client.

Now, the problem is that the demo user we created has a different home directory, but we want it to be the /var/www/example.com/ so when we log in via ftp, then we are automatically “jailed” to this directory.
To change the home directory use this command:

sudo usermod -m -d /var/www/example.com demo

Great. To make sure it worked, you can echo the $HOME variable (you need to be logged in as demo, otherwise it will output the root directory)

echo $HOME

It should output /var/www/example.com
To avoid further issues we need to set the proper permissions on the home folder:

sudo chmod a-w /var/www/example.com

After all set and done, restart the vsftpd process:

sudo service vsftpd restart

Done! Now try to log in via any FTP client with the demo username and password!

Known Issues

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

This error occurs because of the chroot_local_user=YES option in the /etc/vsftpd.conf file.

  • Make sure that you are not using the root account to log in wiht your FTP client.
  • Make sure that the user home directory is indeed correct:
    echo $HOME

    If that's not the desired /var/www/example.com then:

    sudo usermod -m -d /var/www/example.com demo
  • Make sure that the permissions on that directory are correct:
    sudo chmod a-w /var/www/example.com
  • Don't forget to restart your vsftpd server:
    sudo service vsftpd restart

If none of this is helping then you should consider changing the the chroot_local_user option to NO temporary.

Chapters

<< Chapter #5      Chapter #7 >>

Ernest Marcinko

WordPress developer, javascript enthusiast, photoshop clicker and the founder of wp-dreams.com

Stay connected

Related Posts
Filter by
Post Page
Tutorials Wordpress Hosting Blog Testing
Sort by

Saving space automatically – Beginners guide to Digital Ocean

After a while, you will notice an exponential growth of used space, without even copying anything to it. How
2016-05-06 09:24:05
admin

18

Swap file – Beginners guide to Digital Ocean

If you reached this step, your server is up and running flawlessly. However after gaining some traffic it will run out
2015-01-21 15:48:02
admin

18

Mailing – Beginners guide to Digital Ocean

Sending mails properly is probably the hardest task to achieve with Digital Ocean. I will present two ways of doing
2015-01-20 21:38:53
admin

18

Virtual Hosts - Beginners guide to Digital Ocean

By now we have a working private server with very basic features and a demo user. By default your website is data is
2015-01-15 19:23:28
admin

18

From XAMPP to Vagrant WordPress

2016-01-05 19:58:17
admin

8

Comments 1

Leave a Reply

Your email address will not be published. Required fields are marked *