How to Create Virtual Host on Debian Squeeze with vsftpd And MySQL

Vsftpd is considered as the most reliable and quickest FTP servers for Linux. Normally, it is used to work effectively with system users. This tutorial helps in explaining the installation process of vsftpd server that uses virtual users from a MySQL database as an alternative to real system users. Because of this, thousand of ftp users can connect on a single machine and will eventually give high class performance.

In order to administer MySQL database, web based tools like phpMyAdmin can also be used. phpMyAdmin gives you a user friendly graphical interface and you do not have to meddle with the command line predicament.

This document is entirely rooted in Debian Squeeze (Debin 6.0). For this, you need to have a basic Debian Squeeze system.

In this guideline, hostname along with the IP address is used. The settings might vary from system to system, so you have to adjust them accordingly.


  • 1

    Install vsftpd, MySQL And phpMyAdmin

    Since Vsftpd hasn’t any by default support for MySQL, so you have to use PAM to validate against the MySQL database. Therefore, install libpam-mysql along with MySQL, phpMyAdmin and vsftpd.

    apt-get install vsftpd libpam-mysql mysql-server mysql-client phpmyadmin

    You will come across the following questions.

    New password for the MySQL "root" user: <-- yourrootsqlpassword

    Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

    Web server to reconfigure automatically: <-- apache2

    Configure database for phpmyadmin with dbconfig-common? <-- No

  • 2

    Create The MySQL Database For vsftpd

    Now you have to make database with the name of vsftpd and a MySQL user named vsftpd, which will be used by vsftpd daemon after a while in order to link to the vsftpd database:

    mysql -u root –p


    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO 'vsftpd'@'localhost' IDENTIFIED BY 'ftpdpass';

    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO 'vsftpd'@'localhost.localdomain' IDENTIFIED BY 'ftpdpass';


    Now choose a password for the MySQL user vsftpd and replace it with the string ftpdpass.

    USE vsftpd;

    CREATE TABLE `accounts` (


    `username` VARCHAR( 30 ) NOT NULL ,

    `pass` VARCHAR( 50 ) NOT NULL ,

    UNIQUE (





  • 3

    Configure vsftpd

    At the very first, you make a non-privileged user known as vsftpd which is related to the group nogroup. Now run vsftpd under this user domain, and the FTP directories of your virtual users will be in the /home/vsftpd directory (like /home/vsftpd/user1, /home/vsftpd/user2, etc.).

    useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd

    Create a backup of the original /etc/vsftpd.conf file:

    cp /etc/vsftpd.conf /etc/vsftpd.conf_orig

    cat /dev/null > /etc/vsftpd.conf

    vi /etc/vsftpd.conf

    The file should consist of the following code.




















    With the help of user_config_dir option you can easily identify a directory for per-user configuration wp-content/uploads that supersede various parts of global settings. This feature is not compulsory to use and it entirely depends upon you whether you want to use it or not. But anyhow make that directory now:

    mkdir /etc/vsftpd_user_conf

    Now you have to configure PAM, so despite of /etc/passwd and /etc/shadow it can make use of MySQL database to validate virtual FTP users. The PAM configuration for vsftpd is in /etc/pam.d/vsftpd. Create a backup of the original file and now make a new file by following the procedure given below:

    cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd_orig

    cat /dev/null > /etc/pam.d/vsftpd

    vi /etc/pam.d/vsftpd

    auth required user=vsftpd passwd=ftpdpass host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2

    account required user=vsftpd passwd=ftpdpass host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2

    Once you are done with this, restart vsftpd:

    /etc/init.d/vsftpd restart

  • 4

    Make The First Virtual User

    In order to settle the database, use MySQL shell:

    mysql -u root –p

    USE vsftpd;

    Make the virtual user testuser with the password secret.

    INSERT INTO accounts (username, pass) VALUES('testuser', PASSWORD('secret'));


    testuser's homedir is /home/vsftpd/testuser; Sadly, vsftpd doesn’t make that directory by itself if it doesn’t exist. So, make it by yourself and give the ownership rights to vsftpd user and nogroup group:

    mkdir /home/vsftpd/testuser

    chown vsftpd:nogroup /home/vsftpd/testuser

    Start your FTP client program on your system and connect it. The hostname that is used is, username is testuser, and the password is secret.

  • 5

    Database Administration

    It will be convenient for them who are using graphical front-end to MySQL, otherwise you have the option to use phpMyAdmin (in this example under to administrate the vsftpd database.

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + one =