Difference between revisions of "Very Secure FTP Daemon"

From ArchWiki
Jump to: navigation, search
m (codeline -> ic)
m (Fixed "Anonymous logging" typo to "Anonymous login")
Line 26: Line 26:
=== Anonymous logging ===
=== Anonymous login ===
The line in {{Filename|/etc/vsftpd.conf}} controls whether anonymous users can login:
The line in {{Filename|/etc/vsftpd.conf}} controls whether anonymous users can login:
  anonymous_enable=YES # Allow anonymous login
  anonymous_enable=YES # Allow anonymous login

Revision as of 02:51, 10 January 2012

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 (Very Secure FTP Daemon) is a lightweight, stable and secure FTP server for UNIX-like systems.


Vsftpd is included in the official repository. Simply install it with pacman:

# pacman -S vsftpd

The server can be started by using the script below:

# /etc/rc.d/vsftpd start

You can also add vsftpd to your daemon array in Template:Filename if you want it to be started automatically at boot.

See the xinetd section below for procedures to use vsftpd with xinetd.


Most of the settings in vsftpd are done by editing the file Template:Filename. The file itself is well-documented, so this section only highlights some important changes you may want to modify. For all available options and documentation, one can man vsftpd.conf (5). Files are served by default from Template:Filename.

Enabling uploading

The WRITE_ENABLE flag must be set to YES in Template:Filename in order to allow changes to the filesystem, such as uploading:


Local user logging

One must set the line to Template:Filename to allow users in Template:Filename to login:


Anonymous login

The line in Template:Filename controls whether anonymous users can login:

anonymous_enable=YES # Allow anonymous login
no_anon_password=YES # No password is required for an anonymous login
anon_max_rate=30000  # Maximum transfer rate for an anonymous client in bytes per second

Chroot jail

One can set up a chroot environment which prevents the user from leaving its home directory. To enable this, add the following lines to Template:Filename:


The chroot_list_file variable specifies the file which contains users that are jailed.

For a more restricted environment, one can specify the line:


This will make local users jailed by default. In this case, the file specified by chroot_list_file lists users that are not in a chroot jail.

Limiting user login

It's possible to prevent users from logging into the FTP server by adding two lines to Template:Filename:


userlist_file now specifies the file which lists users that are not able to login.

If you only want to allow certain users to login, add the line:


The file specified by userlist_file will now contain users that are able to login.

Limiting connections

One can limit the data transfer rate, number of clients and connections per IP for local users by adding the information in Template:Filename:

local_max_rate=1000000 # Maximum data transfer rate in bytes per second
max_clients=50         # Maximum number of clients that may be connected
max_per_ip=2           # Maximum connections per IP

Using xinetd

If you want to use vsftpd with xinetd, add the following lines to Template:Filename:

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

The option below should be set in Template:Filename:


Finally, add xinetd to your daemons line in Template:Filename. You do not need to add vsftpd, as it will be called by xinetd whenever necessary.

If you get errors like this while connecting to the server:

500 OOPS: cap_set_proc

You need to add capability in MODULES= line in Template:Filename.

While 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

Using SSL to Secure FTP

Generate an SSL Cert, e.g. like that:

# cd /etc/ssl/certs
# openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/certs/vsftpd.pem -out /etc/ssl/certs/vsftpd.pem
# chmod 600 /etc/ssl/certs/vsftpd.pem

You will be asked alot of Questions about your Company etc., as your Certificate is not a trusted one it doesn't really matter what you fill in. You will use this for encryption! If you plan to use this in a matter of trust get one from a CA like thawte, verisign etc.

edit your configuration Template:Filename

#this is important

#choose what you like, if you accept anon-connections
# you may want to enable this
# allow_anon_ssl=NO

#choose what you like,
# it's a matter of performance i guess
# force_local_data_ssl=NO

#choose what you like

#you should at least enable this if you enable ssl...
#choose what you like
#choose what you like
#give the correct path to your currently generated *.pem file
#the *.pem file contains both the key and cert

Tips and tricks

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 Template:Filename 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 rm logins.txt.

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 Template:Filename directory with the following information:

auth required pam_userdb.so db=/etc/vsftpd_login crypt=hash 
account required pam_userdb.so db=/etc/vsftpd_login crypt=hash
Note: 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 Template:Filename 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 Template:Filename 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 Template:Filename:


If the xinetd method is used start the service. You should now only be allowed to login by user-name and password according to the made database.

Adding private folders for the virtual users

First create directories for users:

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

Then, add the following lines to Template:Filename:


More resources