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.
Comments 4
How can I edit my functions.php on DigitalOcean??
I believe…
sudo chmod a-w
(Remove all writing privileges (from any group))
Should actually be…
sudo chmod -R g+w
(Add all writing privileges (to groups that own the files))
(-R recursively. Apply to sub-directories)
Trust me Ernest, FTP is a great tool for editing any sites code but it should be done with CARE! I remember when I added a sloppy code to my functions.php and wp_config.php file and got that dreadful “HTTP ERROR 500, THIS PAGE IS NOT WORKING”.
I use good FTP client like Winscp, which one do you use bro? and which one do you recommend?
Author
Hi,
Indeed, those should be used with care. I personally prefer Notepad++, for easily editing the files directly, and Filezilla for transfering a lot of files.