Automatically Mounting FTP Servers with vsftpd on Ubuntu: Key Techniques and Best Practices
Mounting an FTP server locally on Ubuntu allows seamless access to remote files as if they were on the local filesystem. While vsftpd is primarily an FTP server, you can configure Ubuntu to automatically mount remote FTP directories using tools like curlftpfs (for FTP) or sshfs (for SFTP/SCP). Below are step-by-step techniques to achieve this, including automating the process at boot.
Before mounting, install the necessary utilities:
curlftpfs: For mounting FTP servers (install via sudo apt install curlftpfs).sshfs: For mounting SFTP servers (install via sudo apt install sshfs).fuse: The Filesystem in Userspace kernel module (pre-installed on most Ubuntu versions; install via sudo apt install fuse if missing).These tools enable Ubuntu to interact with FTP/SFTP servers as a local filesystem.
Designate a local directory to serve as the mount point for the remote FTP directory. For example:
sudo mkdir -p /mnt/ftp_remote
Replace /mnt/ftp_remote with your preferred path.
Use curlftpfs to mount the FTP server (replace placeholders with your actual credentials):
sudo curlftpfs -o user=FTP_USERNAME:FTP_PASSWORD,allow_other,uid=$(id -u),gid=$(id -g) ftp://FTP_SERVER_ADDRESS /mnt/ftp_remote
user: Specifies the FTP username and password.allow_other: Allows non-root users to access the mounted directory.uid/gid: Sets the owner of mounted files to the current user (avoids permission issues).sudo curlftpfs -o user=john:secret123,allow_other,uid=$(id -u),gid=$(id -g) ftp://ftp.example.com /mnt/ftp_remote
For SFTP (more secure), use sshfs:
sshfs FTP_USERNAME@FTP_SERVER_ADDRESS:/remote/directory /mnt/ftp_remote -o allow_other,default_permissions
/etc/fstabTo mount the FTP server automatically at system startup, edit the /etc/fstab file (use sudo nano /etc/fstab):
ftp://FTP_SERVER_ADDRESS /mnt/ftp_remote fuse.curlftpfs user=FTP_USERNAME:FTP_PASSWORD,allow_other,uid=$(id -u),gid=$(id -g),auto,user,exec 0 0
auto: Mounts the directory at boot.user: Allows any user to mount/unmount the directory.exec: Permits execution of binaries on the mounted filesystem (if needed).sshfs):FTP_USERNAME@FTP_SERVER_ADDRESS:/remote/directory /mnt/ftp_remote fuse.sshfs delay_connect,_netdev,user,allow_other,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 0 0
_netdev: Ensures the mount waits for the network to be up.reconnect: Automatically reconnects if the connection drops.Note: Storing plaintext passwords in /etc/fstab is insecure. For better security:
~/.ftp_credentials) with 600 permissions and reference it in /etc/fstab:ftp://FTP_SERVER_ADDRESS /mnt/ftp_remote fuse.curlftpfs noauto,user,exec,credentials=/home/youruser/.ftp_credentials,allow_other,uid=$(id -u),gid=$(id -g) 0 0
Contents of ~/.ftp_credentials:user=FTP_USERNAME
password=FTP_PASSWORD
Reboot your system to verify the mount happens automatically:
sudo reboot
After reboot, check if the directory is mounted:
df -h | grep ftp_remote
You should see the remote FTP directory listed.
sudo chown -R $USER:$USER /mnt/ftp_remote) and allow_other is set in /etc/fstab.pasv_enable=YES and pasv_min_port/pasv_max_port to the vsftpd server’s config file (/etc/vsftpd.conf).sudo modprobe fuse) or add it to /etc/modules to load at boot.By following these steps, you can securely and automatically mount an FTP server on Ubuntu, integrating remote files into your local workflow seamlessly.