FTP
FTP (File Transfer Protocol) is a TCP protocol used for downloading files between computers, and it works on a client/server model. The server component, called the FTP daemon, listens for client requests, handles logins, and manages the connection throughout the session. FTP supports two access modes:
Anonymous: Users log in using a default account (usually "anonymous" or "ftp") and provide an email address as the password.
Authenticated: Users must have an account and password, but this method is insecure and not recommended.
FTP does not encrypt data or credentials, making it vulnerable to interception. For secure file transfers, SFTP (SSH File Transfer Protocol) should be used. FTP also limits access to server directories based on the permissions of the login account, usually hiding the root directory and showing only the FTP home directory.
Installing FTP
we can install the FTP daemon using the following commands :
After installation the FTP create the default ftp user and the home directory under /srv/ftp
& If you wish to change this location, to /srv/files/ftp
for example, simply create a directory in another location and change the ftp userâs home directory:
Configuring FTP
The config file of ftp is located on /etc/vsftpd.conf
we can make default config changes. Now we will edit some configs to make the use cases given below.
Disbaling ANONYMOUS Reads/Writes over FTP
To disable the anonymous access we can edit the config file and set the anonymous_enable
& anon_upload_enable
to NO
.
This will ensure that only the authenticated users can access the FTP connections to harden the linux security.
UFW Configuration
If the environment where ufw is enabled we need to make certain changes to make ftp work smoothly
By default the FTP servers use the passive mode connections to enable NAT & traversing firewalls for the connections, we need to config the passive_start & passive_end ports to allow them from the firewall to allow FTP completely from UFW
We will need to add the following lines into the config file
Now we will restart the service to apply the changes
Now we will edit the firewall rule to allow this port range for FTP connections so that we can secure the connections using authenticated FTP & UFW
Now we can see that the authenticated users can connect with ftp
Downloading Files locally using FTP
We can either use terminal or softwares like filezilla to download files from the remote ftp server or even from the browser.
We can also use tools like Filezilla & mobaXterm to get the GUI exprience to download and upload files via FTP
Uploading files via FTP
We need to do some config file changes to enable remote file upload on the ftp server
Look for the configuration FTP write and uncomment and set the write_enabled
parameter value to YES
Restart the service to apply the changes
Uploading files on the remote FTP server
To upload files we can also use GUI tools like filezilla & mobaXterm to make it easier
Securing FTP - Limiting users to Home directory
There are options in /etc/vsftpd.conf
to help make vsftpd more secure. For example users can be limited to their home directories by uncommenting:
You can also limit a specific list of users to just their home directories:
After uncommenting the above options, create a /etc/vsftpd.chroot_list
containing a list of users one per line. Then restart vsftpd:
Also, the /etc/ftpusers
file is a list of users that are disallowed FTP access. The default list includes root, daemon, nobody, etc. To disable FTP access for additional users simply add them to the list.
Encrypting FTP Connections
FTP can also be encrypted using FTPS. Different from SFTP, FTPS is FTP over Secure Socket Layer (SSL). SFTP is a FTP like session over an encrypted SSH connection. A major difference is that users of SFTP need to have a shell account on the system, instead of a nologin shell. Providing all users with a shell may not be ideal for some environments, such as a shared web host. However, it is possible to restrict such accounts to only SFTP and disable shell interaction.
To configure FTPS, edit /etc/vsftpd.conf
and at the bottom add:
Also, notice the certificate and key related options:
By default these options are set to the certificate and key provided by the ssl-cert package. In a production environment these should be replaced with a certificate and key generated for the specific host.
The below screenshots confirms that the FTPS is configured and now the connections is encrypted between the sender & the reciever with SSL/TLS
Last updated