Start by updating our package list and installing the vsftpd daemon:
apt update
apt install vsftpd
Now let’s make a copy of the default conf file for backup.
cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
Open and edit conf file:
vi /etc/vsftpd.conf
Edit or add following lines to the file:
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
pasv_min_port=40000
pasv_max_port=50000
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
If you are using aws ec2 instance, you have to add the below lines also:
listen=YES
listen_ipv6=NO
pasv_address=<Public IP of your instance>
Save and close the file.
Adding a ftp user:
Start by changing permissions of the files in ftp directory as needed:
chown -R www-data:www-data /var/www/html/
find /var/www/html/ -type f -exec chmod 0664 {} \;
find /var/www/html/ -type d -exec chmod 0775 {} \;
Now add a ftp user with above directory as home directory and in the web-server’s group:
useradd -d /var/www/html -g www-data ftpuser
passwd ftpuser
Finally, let’s add our user to /etc/vsftpd.userlist. Use the -a flag to append to the file:
echo “ftpuser” | sudo tee -a /etc/vsftpd.userlist
Restart the daemon to load the configuration changes:
systemctl restart vsftpd