Most of the contents comes from How to Setup FTP Server with VSFTPD on Ubuntu 20.04. Much thanks. 🙂
Why we need this? We have plenty of tools to transfer files to a remote server, such as Xshell & Xftp, Tabby. I recently comes to this problem as I trying to develop an ASP.NET Core Web API project for Linux, when it is more convenient to publish the product via FTP. So here’s how to set up FTP in Linux.
Well, everything starts with this tool.
sudo apt update
Then, it should automatically start. You can verify its status with this.
sudo systemctl status vsftpd
The configuration file for vsftpd is located
/etc/vsftpd.conf, you can refer to VSFTPD.CONF for all available options.
You should have
sudo permission to edit it. And you can use
/ in Vim to search for options more efficiently.
For security reason, we should only allow local users to access FTP.
Locate and uncomment the
write_enable directive to allow filesystem changes, such as uploading and removing files.
To prevent local FTP users to access files outside of their home directories, uncomment the line starting with
chroot_local_user. It is called a “jail” because users are restricted to their own directory.
It is not enough, though. By default, for security reasons, when chroot is enabled, vsftpd will refuse to upload files if the directory that the users are locked in is writable. There are two solutions for this.
This is the recommended one, that is to specify a writeable root. Add the following to entries below
You can set
/home/$USER to allow writing for the entire user directory.
Or, you can simply add this line. Use this option only if you must grant writable access to your user to its home directory.
By default, vsftpd uses active mode. To use passive mode, set the minimum and maximum range of ports. Add these two lines to the configuration file.
Save your configurations, and restart vsftpd service.
sudo systemctl restart vsftpd
If you are running a UFW firewall , you’ll need to allow FTP traffic.
sudo ufw allow 20:21/tcp
Also, open the firewall in your server’s provider’s control panel.
Now, you’re all set! 🥳 You can access FTP with any local user.
There are a few steps ahead, actually, but these are enough for basic use. See How to Setup FTP Server with VSFTPD on Ubuntu 20.04 for more information.
This only enables FTP service, and is not any FTP site. So you cannot visit it in your browser, or even File Explorer. 😞