5

I tried to configure user disk quotas for vsftpd.

I configured quotas for ftp virtual users using the "quota" package on debian (you know, by editing /etc/fstab and all that stuff). Internet told me that it's the only solution with vsftpd.

The problem is : when a file is uploaded on the ftp server, its ownser is ftp:nogroup, so the quota doesn't apply to my user, for example bob:bob.

I also tried to chown ftp:bob the target folder, and use group quota on bob group, but I didn't work

So I went straight to the FAQ and didn't find this :) Do you have any solution on this quota problem ?

Cheers, Mehdi

Castaglia
  • 3,239
  • 3
  • 19
  • 40
user12087
  • 151
  • 1
  • 1
  • 2

3 Answers3

7

Here are the steps you should take to set this up:

VSFTPd

Create the /etc/vsftd.conf file

#nano /etc/vsftpd.conf

listen=YES
anonymous_enable=NO
local_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
download_enable=yes
guest_enable=NO
write_enable=yes

#If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot()
chroot_local_user=no
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

Next create your chroot list to keep users from browsing outside of their home directory

#nano /etc/vsftpd.chroot_list

someusernamehere

SSH

Now since this user has a real account on the system (disk quotas don't work on virual users), you should update SSH if it’s running. Add the following at the bottom line and make sure that the user above is not listed (ie only list users you want to access the server via SSH):

#nano /etc/ssh/sshd_config

AllowUsers username1 username2

Preparing Mount Points

Will will now install and enable quotas

This shows how to do this per user and per group. By the way, quota support is enabled as the file systems are mounted so you’ll need to reboot your server when you complete the following steps. Please don’t do the on a remote machine unless you know exactly what you’re doing.

Perform the following as root or use sudo:

#nano /etc/fstab

You need to have the following in your fstab file (usrquota or grpquota). Here are some examples depending on how you installed your ubuntu server:

/dev/hda1       /home       ext2    defaults,usrquota  1       1 

or

# /home was on /dev/sda3 during installation
UUID=fce47086-925c-4164-80a4-4ba6b307123b /home           ext4    defaults,usrquota        0       2

or

# /home was on /dev/sda3 during installation
UUID=fce47086-925c-4164-80a4-4ba6b307123b /home           ext4    defaults,usrquota,grpquota        0       2

You can remount by rebooting or using the following example:

#mount -o remount,usrquota /home 

Check your mounts:

#mount | grep quota

Load the quota kernel module:

#modprobe quota_v2 echo 'quota_v2' >> /etc/modules 

Setting up you Quotas

Install the quota package.

#apt-get install quota quotatool

Create the following files if they do not already exist. These files store your quota limits:

#touch /home/aquota.user 
#touch /home/aquota.group 
#chmod 600 /home/aquota.user /home/aquota.group 

turn on quatacheck without rebooting:

# quotacheck -vagum

If your kernel supports journaled quota but you are not using it you’ll probably get an error. Use this command in that case:

# quotacheck -fvagum

Set limits for user:

#quotatool -u someusername -bq 100M -l '200 Mb' /home 

The first value is a soft limit, the second is a hard limit. Note that if a user attempts to load a 100Mb text file and they are already over their softlimit by 20Mb, their text file will be truncated by 20Mb to keep them under the 200Mb hard limit.

Check quotas:

#repquota /home 

If ever you wish to remove a quota for a user simply set their hard and soft limits to '0'.

I know it's a lot but that should do it! I ran through the process from scratch before publishing this just to be sure.

Patrick R
  • 2,925
  • 1
  • 18
  • 27
2

Patrick did a good howto. I would add 2 things.

1.) quotatool is not mandatory 2.) If you dont have an own physical partition for you ftp-folders you can use loop-files. I did this and it works really nice

mkdir /usr/loop_device

  • Create a 50MB file f.e

dd if = /dev /zero of = /usr/loop_device/ld1 bs = 1024 count = 50000

  • Create a file system on it

mkfs.ext4 /usr/loop_device/ld1

  • Create a directory for the ftp user

mkdir /home_ftp

  • mount the Loopdevice it

  • add the following entry to the /etc/fstab

/usr/loop_device/ld1 /home_ftp/ ext4 rw,loop,usrquota,grpquota 0 0

i wroted it down here with screenshots:

http://infofreund.de/user_quotas_vsftpd_en/

Bye Chris

chris2k
  • 21
  • 1
1

Quotas work only with system users. So you need to configure vsftp to use system users, you can't use virtual users.

Edit :

Here is a quick and dirty configuration that works :

listen=YES
anonymous_enable=NO
local_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
download_enable=yes
anon_mkdir_write_enable=yes
guest_enable=NO
anon_world_readable_only=no
anon_upload_enable=yes
write_enable=yes
chroot_local_user=no
anon_other_write_enable=yes

Then use "quotacheck" to setup quotas. Don't forget to add the "userquota" option to your fstab.

wazoox
  • 6,782
  • 4
  • 30
  • 62
  • Ok how do you configure quota system users with vsftpd? Because I think we're talking about the same thing. (I understand virtual users are system users and have some kind of "anonymous" status in vsftpd) – user12087 Jul 09 '09 at 08:12
  • Virtual users are internal to vsftpd and all use the same actual system ftp user. System users are real users that you can log onto the system with using ssh or whatever. You should use "local_enable=YES" and setup quotas ( see "man quota") on user directories. You may want to chroot local users, too. – wazoox Jul 09 '09 at 12:48
  • I'm confused.. I already have local_enable=YES and log in with system users, but when I write a file, the ownership is the actual system ftp user (as you name it) any idea what's wrong ? – user12087 Jul 09 '09 at 15:55
  • what I was naming "virtual users" was in fact this setting "guest_enable=YES". I'm re-checking my conf.. – user12087 Jul 09 '09 at 15:56