How to Set Up an FTP Server on Ubuntu

Published October 27, 2024
How to Set Up an FTP Server on Ubuntu
Cheap Dedicated Server

How to Set Up an FTP Server on Ubuntu


 

 

Setting up an FTP server on Ubuntu can be a straightforward way to allow remote file sharing and transfers. This guide will walk you through setting up an FTP server using vsftpd (Very Secure FTP Daemon), one of the most popular and secure FTP servers for Linux. By the end of this guide, you’ll have a working FTP server with a user login and customized permissions.


How to Set Up an FTP Server on Ubuntu

Step 1: Update Your System

First, ensure your package lists are up-to-date to avoid any issues with outdated repositories.

 

sudo apt update

sudo apt upgrade -y

 


Step 2: Install vsftpd

Ubuntu’s default repositories include vsftpd, so installing it is as easy as running the command:

Install vsftpd

 

sudo apt install vsftpd -y

 

Once installed, the vsftpd service should automatically start. You can check its status using:

vsftpd service should automatically start

 

sudo systemctl status vsftpd

 

You should see an output indicating that it is active and running.


Step 3: Configure vsftpd

Before you configure vsftpd, it’s a good idea to make a backup of the default configuration file:
Configure vsftpd

 

sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak

 

Now, open the configuration file in your preferred text editor:

open the configuration file in your preferred text editor

 

sudo nano /etc/vsftpd.conf

 

Make the following changes for a basic setup:

  • Enable Local User Access: Allow local users to log in by uncommenting the following line:
    Enable Local User Access
     

    local_enable=YES

     

  • Allow Write Access: To allow users to upload, delete, and modify files, uncomment this line:
    Allow Write Access
     

    write_enable=YES

     

  • Limit Users to Their Home Directory: To restrict users to their home directory, uncomment this line:
    Limit Users to Their Home Directory
     

    chroot_local_user=YES

     

  • Optional – Enable Passive Mode: Passive mode is recommended for users connecting behind firewalls. Add the following lines at the end of the configuration file:
    Optional - Enable Passive Mode
     

    pasv_enable=YES

    pasv_min_port=10000

    pasv_max_port=10100

     

Once you’ve made these changes, save and close the file (Ctrl + X, then Y to confirm and Enter to exit).


Step 4: Restart the vsftpd Service

To apply the new settings, restart the vsftpd service:

 

sudo systemctl restart vsftpd

 


Step 5: Add an FTP User

For security, create a dedicated FTP user rather than allowing root access.

  1. Add a New User:
     

    sudo adduser ftpuser

     

    Follow the prompts to set a password and other details.

  2. Set Permissions: Adjust permissions for the user’s home directory as needed:
     

    sudo chmod -R 755 /home/ftpuser

     

Now, the ftpuser can use their username and password to access the FTP server.


Step 6: Open the FTP Ports in Firewall (if Enabled)

If you have a firewall enabled, open port 21 (FTP’s default port) and the range of passive ports specified in the vsftpd configuration.

 

sudo ufw allow 21/tcp

sudo ufw allow 10000:10100/tcp

 

Reload the firewall settings to apply changes:

 

sudo ufw reload

 


Step 7: Test the FTP Connection

To verify that your FTP server is working, you can use an FTP client like FileZilla or the command line:

 

ftp localhost

 

When prompted, enter the username and password of ftpuser. If everything is configured correctly, you should be able to navigate to the user’s home directory and upload or download files.


Additional Security Tips

  1. Disable Anonymous Access: Ensure that anonymous_enable=NO is set in the vsftpd configuration to prevent anonymous users from accessing your server.
  2. Limit User Access to Specific Folders: If you want to restrict users to specific folders, use chmod to set appropriate permissions on directories.
  3. Enable SSL/TLS: For secure file transfers, consider configuring vsftpd with SSL/TLS. You can install OpenSSL and add SSL settings to /etc/vsftpd.conf for encrypted connections.
  4. Regularly Monitor the FTP Logs: Logs are stored in /var/log/vsftpd.log. Check these files periodically for any suspicious activity.

Conclusion

You’ve now set up a secure FTP server on Ubuntu with vsftpd. This guide provides a basic configuration suitable for internal or low-security applications. For high-security environments, consider additional measures like setting up SSL/TLS encryption and restricting access based on IP addresses.

How to Set Up an FTP Server on Ubuntu (F.A.Q)

w can I restart vsftpd after configuration changes?

To apply new settings, restart the vsftpd service:

 
sudo systemctl restart vsftpd
 

How do I limit FTP users to their home directory?

In the configuration file (/etc/vsftpd.conf), set:

 
chroot_local_user=YES
 
This will restrict users to their own home directories.

How can I enable FTP passive mode?

Add these lines to the end of /etc/vsftpd.conf to enable passive mode:

 
pasv_enable=YES
pasv_min_port=10000
pasv_max_port=10100

This helps users connect from behind firewalls.

 

How do I open the FTP port in the firewall?

If the firewall is active, open the default FTP port (21) and the passive port range:

 
sudo ufw allow 21/tcp
sudo ufw allow 10000:10100/tcp
sudo ufw reload