Installing and Configuring an FTP Server in Ubuntu

Administration 4 min read

One of the most convenient and intuitive ways to work with files and transfer them between servers or between your local computer and a remote linux server is an FTP server. In this quick guide, we will show you simple steps to easily install and configure an FTP server.

 

 

First, let's make sure your Ubuntu operating system is up to date by running the following command:


sudo apt update && sudo apt upgrade -y

 


Once your system is updated, you can begin installing the software to run your FTP server. For Ubuntu we will use the vsftpd package, a lightweight and secure FTP server.

To install vsftpd, run the following command in a terminal:


sudo apt install vsftpd

 


After installation, vsftpd should start immediately. However, it is recommended to double check its status to make sure everything is working as expected. You can do this by running:


sudo systemctl vsftpd status

 

If the service is active and running, you are ready to move on to the configuration phase.

 

 

Next, we'll configure vsftpd to tailor it to your specific needs. The vsftpd configuration file is located at /etc/vsftpd.conf. You can open it using your favorite text editor. For example:

 

sudo nano /etc/vsftpd.conf

 

 


In the configuration file you will find various options to configure your FTP server. Here are some key configurations you may want to consider:

 

Anonymous FTP: Determine whether you want to allow anonymous FTP access. You can enable or disable this feature by changing the value of anonymous_enable.

Local Users: Decide whether local system users are allowed access to the FTP server. You can control this using the local_enable option.

FTP Root Directory: Set a directory to serve as the root directory of your FTP server. The default is usually /srv/ftp. You can change this using the local_root option.

User Permissions: Specify permissions for uploaded files by configuring write_enable and local_umask.

 

You can familiarize yourself with all possible FTP server parameters in the official manual.


A typical configuration might be something like this:

secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=ftp
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
local_root=/home/ftpuser
allow_writeable_chroot=YES
user_sub_token=$USER
local_root=/home/$USER/ftp
pasv_min_port=40000
pasv_max_port=50000
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO

 

After making the desired changes, save the configuration file and exit the text editor.

 

Next, for our configuration to work, we need to create a new user named ftpuser and the home directory /home/ftpuser, which will contain the downloaded files. Let's create a user and set a password for it using the commands:

 

sudo useradd -m -d /home/ftpuser ftpuser
sudo passwd ftpuser

 


To ensure greater security, we must also create a list of users who will be allowed access to the FTP server. In this file we simply indicate the login of the required user, and if there are several of them, then there is one login in each new line.

 

cat > /etc/vsftpd.userlist

ftpuser


In the penultimate line of the configuration file we indicated where the userlist will be stored.

 


After making configuration changes, you need to restart the vsftpd service for the changes to take effect. You can do this by running:

 

sudo systemctl restart vsftpd

 

 

Congratulations! You have successfully installed and configured an FTP server on your Ubuntu system. Now you can start transferring files to and from the server securely.

Be sure to configure your firewall to allow FTP traffic if you have a firewall enabled on your system. You can open the FTP port (usually port 21) using ufw or your preferred firewall configuration tool. For example:

 

sudo ufw allow 21

 

That's all! Now you are ready to take advantage of your own FTP server in Ubuntu. Happy file transfer!

2024-02-07 06:42