viki - vsftpd Wiki

You are here :

 Virtual Users

Monday, 19. March 2007 09:38:22, by WikiMeandrain

 

Contents

Howto setup Virtual users with MySQL:

First of all, I am using FreeBSD 6.1 so, if you are using Linux, settings coud be a little different. (Keep in mind that i've used man page of vsftpd so, the only difference is the location of config files. For example FreeBSD keeps userland apps config files in /usr/local/etc instead of /etc.

So here is the configuration process:

Step 1

Create a file in /etc/pam.d, called vsftpd with the following content

#echo "auth required /usr/local/lib/pam_mysql.so verbose=1 user=vsftpd passwd=123456 host=localhost 
 db=vsftpddb table=vsftpdtable usercolumn=username passwdcolumn=passwd crypt=2" >vsftpd

echo "account required /usr/local/lib/pam_mysql.so verbose=1 user=vsftpd passwd=123456 host=localhost 
 db=vsftpddb table=vsftpdtable usercolumn=username passwdcolumn=passwd crypt=2

Where: vsftpd is a mysql user, with password 123456
vsftpddb = vsftpd mysql database
vsftpdtable = a table from vsftpd mysql database

Step 2:

Create a mysql database: vsftpddb with vsftpdtable table.

The vsftpd table has the following fields: mysql> describe vsftpdtable;

+----------+------------------+------+-----+---------------------+-------+
| Field    | Type             | Null | Key | Default             | Extra |
+----------+------------------+------+-----+---------------------+-------+
| username | varchar(30)      |      | PRI |                     |       |
| passwd   | varchar(80)      |      |     |                     |       |
| email    | varchar(80)      |      |     |                     |       |
| uid      | int(11) unsigned | YES  |     | 1002                |       |
| gid      | int(11) unsigned | YES  |     | 1002                |       |
| homedir  | varchar(255)     | YES  |     | NULL                |       |
| shell    | varchar(255)     | YES  |     | NULL                |       |
| active   | tinyint(1)       |      |     | 0                   |       |
| count    | int(11)          |      |     | 0                   |       |
| accessed | datetime         |      |     | 0000-00-00 00:00:00 |       |
| modified | datetime         |      |     | 0000-00-00 00:00:00 |       |
+----------+------------------+------+-----+---------------------+-------+

Step 3

Edit /usr/local/etc/vsftpd.conf (if you are using Linux, then it is /etc/vsftpd.conf) and add the following options:

pam_service_name=vsftpd
guest_enable=YES
guest_username=john
local_root=/home/john/temp
chown_uploads=YES
chown_username=john
virtual_use_local_privs=YES
chroot_local_user=YES
write_enable=YES
user_config_dir=/usr/local/etc/vsftpd

You must have user john in your system

Step 4

Create a directory /usr/local/etc/vsftpd

In this directory add a file "test" with the following content

#chroot_local_user=YES
local_root=/home/test
chown_uploads=YES
chown_username=test
write_enable=YES
guest_username=test
pam_service_name=vsftpd

This user must exist in your mysql database:

+----------+-------------------------------------------+-------+------+------+----------------------+---------------+--------+-------+---------------------+---------------------+
| username | passwd                                    | email | uid  | gid  | homedir              | shell         | active | count | accessed            | modified            |
+----------+-------------------------------------------+-------+------+------+----------------------+---------------+--------+-------+---------------------+---------------------+
| test     | *60BDA3574A7039ECC736DDBDFA9D9208C144A964 |       | 1002 | 1002 |                      |               |      0 |     0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+----------+-------------------------------------------+-------+------+------+----------------------+---------------+--------+-------+---------------------+---------------------+

To have this record into mysql database go to mysql client and type: mysql>insert into vsftpdtable values('test', password('123456'), ' ',' ',' ',' ',' ',' ',' ',' ',' ');

This is my example, you might need all fields into the database.

Comments

Auth mysql

Tuesday, 3. July 2007 09:27:27, by

Hey,

is it possible to configure the user home directory over mysql?

Mirandus

Nope

Wednesday, 28. November 2007 09:00:36, by Daniel Khalil

Nope, it isn't. You'd have to use a per user config to define a home directory for each user.