Very Secure FTP Daemon

From ArchWiki
Revision as of 20:44, 20 June 2010 by Sun-doctor (talk | contribs)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

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 -S 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 -S xinetd vsftpd

The following configuration files will need to be changed:


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

/etc/hosts.allow - add following entry (for security reasons hosts.allow could be configured differently /etc/hosts.deny and /etc/hosts.allow):

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

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:


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/ db=/etc/vsftpd_login crypt=hash 
account required /lib/security/ db=/etc/vsftpd_login crypt=hash

Attention! We use /etc/vsftpd_login without .db extension in PAM-config! 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:


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.

To add private folders for the virtual users

First create their directories

# mkdir /srv/ftp/user1
# mkdir /srv/ftp/user2
# chown virtual:virtual /srv/ftp/user?/

Again, in your vsftpd.conf file, add the following.