Configuring Virtual Hosts for Ubuntu FTP Server (vsftpd)
To set up virtual hosts on an Ubuntu FTP server using vsftpd (Very Secure FTP Daemon), follow these structured steps. Virtual hosting allows a single FTP server to serve multiple domains or users with isolated directories.
Update your package list and install vsftpd:
sudo apt update
sudo apt install vsftpd
Edit the main configuration file (/etc/vsftpd.conf) to enable virtual hosting and basic security:
sudo nano /etc/vsftpd.conf
Make the following changes:
local_enable=YESwrite_enable=YESchroot_local_user=YESallow_writeable_chroot=YESvirtual_use_local_privs=YES and user_sub_token=$USERlocal_root=/home/$USERanonymous_enable=NOSave and exit the editor.
For each virtual host (e.g., user1, user2), create a dedicated directory and set ownership:
sudo mkdir -p /home/user1/ftp
sudo mkdir -p /home/user2/ftp
sudo chown user1:user1 /home/user1/ftp
sudo chown user2:user2 /home/user2/ftp
sudo chmod 755 /home/user1/ftp
sudo chmod 755 /home/user2/ftp
Replace user1, user2 with your desired usernames and adjust directory paths as needed.
Each virtual host requires a system user to associate with its directory. Create users without shell access (for security):
sudo adduser user1 --shell /usr/sbin/nologin
sudo adduser user2 --shell /usr/sbin/nologin
Set strong passwords when prompted.
Apply configuration changes by restarting the service:
sudo systemctl restart vsftpd
Allow FTP traffic (port 21) and passive mode ports (typically 40000–50000) using UFW:
sudo ufw allow 21/tcp
sudo ufw allow 40000:50000/tcp
sudo ufw reload
Use an FTP client (e.g., FileZilla) to verify connectivity:
user1 (or the virtual host username)You should be restricted to the corresponding directory (e.g., /home/user1/ftp). Repeat for each virtual host.
anonymous_enable=NO) in production. Use strong passwords and consider enabling SSL/TLS (FTPS) for encrypted connections./var/log/vsftpd.log for troubleshooting (e.g., login failures, permission errors).By following these steps, you can successfully configure virtual hosts on an Ubuntu FTP server using vsftpd, providing isolated storage for multiple users or domains.