Server FTP
File Transfer Protocol (FTP) is a TCP protocol for downloading files between computers. In the past, it has also been used for uploading but, as that method does not use encryption, user credentials as well as data transferred in the clear and are easily intercepted. So if you are here looking for a way to upload and download files securely, see the section on OpenSSH in Amministrazione remota instead.
FTP works on a client/server model. The server component is called an FTP daemon. It continuously listens for FTP requests from remote clients. When a request is received, it manages the login and sets up the connection. For the duration of the session it executes any of commands sent by the FTP client.
L'accesso a un server FTP può essere gestito in due modi:
-
Anonimo
-
Con autenticazione
In the Anonymous mode, remote clients can access the FTP server by using the default user account called "anonymous" or "ftp" and sending an email address as the password. In the Authenticated mode a user must have an account and a password. This latter choice is very insecure and should not be used except in special circumstances. If you are looking to transfer files securely see SFTP in the section on OpenSSH-Server. User access to the FTP server directories and files is dependent on the permissions defined for the account used at login. As a general rule, the FTP daemon will hide the root directory of the FTP server and change it to the FTP Home directory. This hides the rest of the file system from remote sessions.
vsftpd - Installazione del server FTP
vsftpd is an FTP daemon available in Ubuntu. It is easy to install, set up, and maintain. To install vsftpd you can run the following command:
sudo apt-get install vsftpd
Configurazione anonima di FTP
By default vsftpd is not configured to allow anonymous download. If you wish to enable anonymous download edit /etc/vsftpd.conf by changing:
anonymous_enable=Yes
During installation a ftp user is created with a home directory of /srv/ftp. This is the default FTP directory.
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:
sudo mkdir /srv/files/ftp sudo usermod -d /srv/files/ftp ftp
Applicate le modifiche, riavviare vsftpd:
sudo restart vsftpd
Finally, copy any files and directories you would like to make available through anonymous FTP to /srv/files/ftp, or /srv/ftp if you wish to use the default.
Configurazione FTP per utenti autenticati
By default vsftpd is configured to authenticate system users and allow them to download files. If you want users to be able to upload files, edit /etc/vsftpd.conf:
write_enable=YES
Riavviare vsftpd:
sudo restart vsftpd
Ora, quando gli utenti accedono via FTP, il loro punto di partenza sarà la propria directory home, dove potranno scaricare e caricare file e creare directory.
Similarly, by default, anonymous users are not allowed to upload files to FTP server. To change this setting, you should uncomment the following line, and restart vsftpd:
anon_upload_enable=YES
Abilitare il caricamento anonimo di file via FTP può compromettere la sicurezza del sistema. È sconsigliato abilitare il caricamento anonimo su server collegati direttamente a Internet.
Il file di configurazione è composto da diversi parametri di configurazione, le cui informazioni sono disponibili nel file stesso. In alternativa, è possibile fare riferimento alla pagina man (man 5 vsftpd.conf).
FTP sicuro
All'interno del file di configurazione /etc/vsftpd.conf di vsftpd, sono presenti molte opzioni per rendere il programma più sicuro. Per esempio, togliendo il commento a quanto segue, gli utenti possono essere limitati all'utilizzo solo della propria directory personale:
chroot_local_user=YES
È anche possibile limitare un particolare gruppo di utenti all'utilizzo delle sole directory personali:
chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list
Tolto il commento alle opzioni precedenti, creare un file /etc/vsftpd.chroot_list con l'elenco degli utenti, uno per riga, quindi riavviare vsftpd:
sudo restart vsftpd
Inoltre, il file /etc/ftpusers contiene un elenco di utenti a cui è negato l'accesso FTP. L'elenco comprende gli utenti root, daemon, nobody, ecc... Per disabilitare l'accesso FTP ad altri utenti, aggiungerli semplicemente a questo elenco.
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. See the section on OpenSSH-Server for more.
Per configurare FTPS, modificare il file /etc/vsftpd.conf aggiungendo:
ssl_enable=Yes
Inoltre, notare anche le opzioni relative al certificato e alla chiave:
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
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. For more information on certificates see Certificati.
Riavviare vsftpd e gli utenti non-anonimi utilizzeranno FTPS:
sudo restart vsftpd
Per consentire accesso FTP agli utenti dotati di una shell /usr/sbin/nologin, ma non dispongono di accesso shell, modificare il file /etc/shells aggiungendo nologin:
# /etc/shells: valid login shells /bin/csh /bin/sh /usr/bin/es /usr/bin/ksh /bin/ksh /usr/bin/rc /usr/bin/tcsh /bin/tcsh /usr/bin/esh /bin/dash /bin/bash /bin/rbash /usr/bin/screen /usr/sbin/nologin
Questo è necessario poiché, in modo predefinito, vsftpd utilizza PAM per l'autenticazione e i file di configurazione /etc/pam.d/vsftpd contiene:
auth required pam_shells.so
Il modulo shells di PAM limita l'accesso alle shell indicate nel file /etc/shells.
Most popular FTP clients can be configured to connect using FTPS. The lftp command line FTP client has the ability to use FTPS as well.
Riferimenti
-
Per maggiori informazioni, consultare il sito web di vsftpd.
-
For detailed /etc/vsftpd.conf options see the vsftpd.conf man page.