FTP, or File Transfer Protocol, is a standard protocol for sending and receiving files from remote servers. It is easier to use than command line alternatives like scp
, especially with graphical interfaces such as FileZilla.
What is FTP?
In the old days of the Internet, public FTP servers were a very common way of making files available to a large number of people. Today, FTP is still around and widely used for administrative tasks.
While some form of FTP CLI ships with most major operating systems, GUI clients like FileZilla make the process of moving files between servers as easy as dragging and dropping from local storage to remote storage. , or vice versa. All underlying traffic is handled via FTP.
To configure this, you need to install and configure an FTP server, such as vsftpd
, on the remote machine you want to access.
It should be noted that users logged in via FTP will have access to your system, just like you. You can take steps to mitigate these risks, such as accessing the whitelist and locking out users in their home directories.
Installing vsftpd
To get started, install vsftpd
from your distribution’s package manager. For Debian-based systems like Ubuntu, this would be apt
:
sudo apt-get install vsftpd
Next, you’ll need to start the service and configure it to run on startup:
systemctl start vsftpd
systemctl enable vsftpd
FTP has two main authentication methods:
- Anonymous FTP, where anyone can connect without a password. This is used for public file sharing and is disabled by default.
- Local user login, which allows any user
/etc/passwd
to access FTP using a user name and password.
You will probably want to enable local user login and disable anonymous access. Logging in to FTP using your user account will give you access to everything your account can access.
Open up /etc/vsftpd.conf
in your favorite text editor and replace the following line with YES
:
local_enable=YES
If you want to be able to download files, change write_enable
To YES
also:
write_enable=YES
With a restart of vsftpd
(systemctl restart vsftpd
), you should now be able to connect to FTP using a client such as FileZilla or the CLI on your home computer.
If you only want to enable FTP for specific users, you can add access to the whitelist. Open up /etc/vsftpd.userlist
, and add the names of each account you want to activate on separate lines.
nano /etc/vsftpd.userlist
Then add the following lines to /etc/vsftpd.conf
:
userlist_enable=YES userlist_file=/etc/vsftpd.userlist userlist_deny=NO
This will limit access to only the users defined in the userlist file and deny all others.
If you don’t want users to access files outside of their home directory, you can put them in a chroot jail, which will prevent them from interacting with top-level directories. You can activate it by uncommenting the following line in /etc/vsftpd.conf
:
chroot_local_user=YES
Restart vsftpd
with systemctl restart vsftpd
to apply the changes.
FTPS configuration
Standard FTP traffic is sent unencrypted as HTTP. This is obviously not great, so you should configure vsftpd
to encrypt traffic with TLS.
To do this, generate a new key and sign a request with openssl
:
openssl genrsa -des3 -out FTP.key
openssl req -new -key FTP.key -out certificate.csr
vsftpd
needs the password removed from this key, so copy the key and forward it to openssl
:
cp FTP.key FTP.key.orig openssl rsa -in FTP.key.orig -out ftp.key
Finally, generate a TLS certificate using this key:
openssl x509 -req -days 365 -in certificate.csr -signkey ftp.key -out mycertificate.crt
Copy the key and certificate to /etc/pki/tls/certs/
:
cp ftp.key /etc/pki/tls/certs/ cp mycertificate.crt /etc/pki/tls/certs
Now that all the certificates are configured, you can open again /etc/vsftpd.conf
, and add the following lines:
ssl_enable=YES allow_anon_ssl=YES ssl_tlsv1=YES ssl_sslv2=NO ssl_sslv3=NO rsa_cert_file=/etc/pki/tls/certs/mycertificate.crt rsa_private_key_file=/etc/pki/tls/certs/ftp.key ssl_ciphers=HIGH require_ssl_reuse=NO
Restart vsftpd
with systemctl restart vsftpd
to apply the changes.