Very Secure FTP Daemon

From ArchWiki
Revision as of 20:34, 14 January 2010 by Skatias (Talk | contribs) (PAM with "virtual users")

Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end vsftpd is the "very secure ftp daemon", a small FTP server.

Because it will run either with or without xinetd, this article will cover both methods.

Without xinetd (simpler)

If you want to avoid the extra complications of xinetd, just grab the package:

# pacman -Sy vsftpd

then edit /etc/vsftpd.conf and set listen=YES. These are useful options (optional):

listen=YES          # Lets vsftpd act as a stand alone server
anonymous_enable=NO # Assuming you do not want anonymous ftp
local_enable=YES    # This lets local machine users log in
write_enable=YES    # Be really careful using this with anonymous_enable=YES

After that, append 'vsftpd: ALL' to your /etc/hosts.allow file. You can then start the server with /etc/rc.d/vsftpd start. Add it to your DAEMONS list in /etc/rc.conf if you want it to start at bootup.

Using xinetd

First, grab the packages you will need with pacman:

# pacman -Sy xinetd vsftpd

The following configuration files will need to be changed:

/etc/xinetd.d/vsftpd:

service ftp
{
        socket_type             = stream
        wait                    = no
        user                    = root
        server                  = /usr/sbin/vsftpd
        log_on_success  += HOST DURATION
        log_on_failure  += HOST
        disable                 = no
}

/etc/vsftpd.conf is a very well documented configuration file, but here are the basics you will probably want to set:

anonymous_enable=NO      # Assuming you do not want anonymous ftp
local_enable=YES         # This lets local machine users log in
write_enable=YES    # Be really careful using this with anonymous_enable=YES
tcp_wrappers=YES    # Use tcp_wrappers to control connections. Then allow in hosts.allow
pam_service_name=vsftpd

/etc/hosts.allow - add following entry:

vsftpd: ALL

Finally, add xinetd to your daemons line in /etc/rc.conf. You do not need to add vsftpd, as it will be called by xinetd whenever necessary.

If you get errors like

500 OOPS: cap_set_proc

when connecting to the server, you need to add capability in MODULES= line in /etc/rc.conf.


When upgrading to version 2.1.0 you might get an error like this when connecting to the server from a client:

500 OOPS: could not bind listening IPv4 socket

In earlier versions it has been enough to leave the following lines commented:

# Use this to use vsftpd in standalone mode, otherwise it runs through (x)inetd
# listen=YES

In this newer version, and maybe future releases, it is necessary however to explicitly configure it to not run in a standalone mode, like this:

# Use this to use vsftpd in standalone mode, otherwise it runs through (x)inetd
listen=NO

PAM with "virtual users"

Using virtual users has the advantage of not requiring a real login account on the system. Keeping the environment in a container is of course a more secure option.

A virtual users database has to be created by first making a simple text file like this:

user1
password1
user2
password2

Include as many virtual users as you wish according to the structure in the example. Save it as logins.txt; the file name does not have any significance. Next step depends on Berkeley database system, which is included in the core system of Arch. As root create the actual database with the help of the logins.txt file, or what you chose to call it:

# db_load -T -t hash -f logins.txt /etc/vsftpd_login.db

It is recommended to restrict permissions for the now created vsftpd_login.db file:

# chmod 600 /etc/vsftpd_login.db
Warning: Be aware that stocking passwords in plain text is not safe. Don't forget to remove your temporary file with Template:Codeline.

PAM should now be set to make use of vsftpd_login.db. To make PAM check for user authentication create a file named ftp in the /etc/pam.d/ directory with the following information:

auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login crypt=hash 
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login crypt=hash

Now it is time to create a home for the virtual users. In the example /srv/ftp is decided to host data for virtual users, which also reflects the default directory structure of Arch. First create the general user virtual and make /srv/ftp its home:

# useradd -d /srv/ftp virtual

Make virtual the owner:

# chown virtual:virtual /srv/ftp

Configure vsftpd to use the created environment by editing /etc/vsftpd.conf. These are the necessary settings to make vsftpd restrict access to virtual users, by user-name and password, and restrict their access to the specified area /srv/ftp:

anonymous_enable=NO
local_enable=YES
chroot_local_user=YES
guest_enable=YES
guest_username=virtual
virtual_use_local_privs=YES

If the xinetd method is used start the sevice, i.e. '/etc/rc.d/xinetd start'. You should now only be allowed to login by user-name and password according to the made database.