FTP Server Configure

In this post, we will see how we can install an FTP server on our Ubuntu Server in order to transfer files between the server and other clients.
We will use the vsftpd
service, to create the FTP server and we will access it either as a new ftpuser
authenticated user or Anonymously without authentication.
If you are going to use the FTP service remotely on the public internet, it is best to not use Anonymous FTP, as anyone will be able to download from the server. Also, another and safer option is to use SFTP for remote transferring file that uses SSH, but for local network transfers a normal FTP service will be fine.
Install the FTP framework
Install the FTP framework:
Configure firewall
If we have a firewall running we must enable the FTP port in order to access the server. The default ports for FTP are port 20
, port 21
and the range of passive ports can be port 49152-65535
.
For a firewall like ufw
, we can enable the FTP by running the following commands:
But we can also manually enable the ports to limit the range of passive ports to port 10000-10100
:
Install FileZilla (on client)
Install FileZilla on a client computer in order to test the FTP server:
Authenticated FTP
Creating ftpuser user
We will create a dedicated FTP user that we will use only for FTP with minimum privileges in order to be more safe.
Firstly create the ftpuser
user:
Add a password when prompted.
FTP is generally more secure when users are restricted to a specific directory. vsftpd
accomplishes this with chroot
jails. When chroot
is enabled for local users, they are restricted to their home directory by default. However, because of the way vsftpd
secures the directory, it must not be writable by the user. This is fine for a new user who should only connect via FTP, but an existing user may need to write to their home folder if they also have shell access.
Because we don’t want to disable write privileges completely from the home directory, we will create a server
directory inside the ftpuser
’s home directory that will be used to host all the files for the FTP service.
Create the server
directory:
Set the ownership to the ftpuser
user:
Disable write access:
FTP configuration file
We are going to make some changes to the default config file of vsftpd
, so it is best to take a copy of the default file if something goes wrong or you want to go back to the default settings:
Now we are going to edit the vsftpd.conf
file:
Make sure this settings are the same:
Also, enable users to upload files by changing the write_enable
setting:
We will also enable the chroot_local_user
setting to restrict access outside the specified FTP directory:
We will, add a user_sub_token
to insert the username in our local_root
directory path so our configuration will work for the ftp
user and any additional future users we would want o add:
We will limit the range of passive ports to the ones we selected to enable on the firewall:
To allow only the users we will specify we want to enable a userlist to add the users:
The userlist_deny=NO
setting is used to permit only users in the userlist
to have FTP access.
In the /etc/vsftpd.userlist
we will add the users we want:
And we will check if the list is ok:
Restart the daemon to make changes take effect:
Test FTP Access
Lets first try to connect anonymously to test that we will fail:
Output:
We see that access was denied as expected.
Close the connection:
Now lets try accessing with the ftpuser
user:
Output:
We now have access as expected.
Close the connection:
Anonymous FTP
In this section we will see how to setup vsftpd
to allow only anonymous users to access FTP, so anyone can access the server without having an account, and we will disallow user account to access the FTP server.
For anonymous FTP, the default location for the files is under /srv/ftp
. If we want to change this location we will have to create the directory and specify it in the configuration file.
Create ftp directory
In order to change the default location for the files we have to create a new directory:
And change the ownership to nobody:nogroup
. Later we will configure to show all files as being owned by the existing ftp
user and group:
And create a test file to check later:
FTP configuration file
Make sure this settings are the same:
Also, if you want anonymous users to upload files, you do that by changing the write_enable
setting:
We will limit the range of passive ports to the ones we selected to enable on the firewall:
Some other useful settings are the following:
And lastly, to change the default file location, to /var/ftp
we specify it with:
Restart the daemon to make changes take effect:
Test FTP Access
Lets try connecting anonymously to test the connection:
Output:
We now have access as expected.
In the Name
section we can either try the anonymous
or the ftp
user.
Close the connection:
We can also access the ftp server from the browser at: