温馨提示×

Debian FTP服务器磁盘配额

小樊
55
2025-09-22 19:06:03
栏目: 云计算

Debian FTP Server Disk Quota Configuration Guide

Disk quotas help control disk space usage by FTP users, preventing any single user from monopolizing storage. Below are step-by-step instructions to set up user and group quotas on a Debian FTP server.

1. Install Required Packages

First, install the quota package (mandatory for quota management) and optionally quota-nls (for localized error messages). Run:

sudo apt update
sudo apt install quota quota-nls

2. Modify /etc/fstab for Quota Support

Edit the /etc/fstab file to enable user (usrquota) and/or group (grpquota) quotas for the partition hosting FTP files (e.g., /home). Locate the target partition (e.g., /dev/sda1) and append the options:

/dev/sda1 /home ext4 defaults,usrquota,grpquota 0 2

Save changes and exit the editor.

3. Remount the Partition

Apply the new mount options without rebooting by remounting the partition:

sudo mount -o remount /home

4. Initialize Quota Database

Create the quota database files (aquota.user for users, aquota.group for groups) using quotacheck. The -c flag creates new databases, -u enables user quotas, -g enables group quotas, and -m forces a check even if the system is running:

sudo quotacheck -cum /home

5. Enable Disk Quotas

Start the quota service to enforce limits immediately:

sudo quotaon -vug /home

The -v flag shows verbose output, -u enables user quotas, and -g enables group quotas.

6. Configure User/Group Quotas

Use edquota to set soft (warning threshold) and hard (strict maximum) limits for users/groups. Replace username with the actual FTP user’s name:

sudo edquota -u username

This opens an editor with a section like this:

Disk quotas for user username (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda1                        10240    51200      65536        100      200      250
  • blocks: Current disk usage (in KB).
  • soft: Warning threshold (e.g., 50GB soft limit = 51200 blocks × 1KB).
  • hard: Maximum allowed space (e.g., 60GB hard limit = 65536 blocks × 1KB).
  • inodes: Limits for the number of files (adjust similarly).

Save and exit to apply changes. For group quotas, use edquota -g groupname.

7. Verify Quota Settings

Check a user’s quota usage with:

quota -u username

For a summary of all users, run:

quota -vug /home

The repquota command provides a detailed report:

sudo repquota /home

8. Configure FTP Server for Quota Support

If using vsftpd (common for Debian FTP servers), edit its configuration file to enable quota integration:

sudo nano /etc/vsftpd.conf

Add/modify these lines:

quota_enable=YES
quota_file=/var/lib/vsftpd/quota.user
quota_group_enable=YES
quota_group_file=/var/lib/vsftpd/quota.group

Restart vsftpd to apply changes:

sudo systemctl restart vsftpd

Key Notes

  • Replace /home and /dev/sda1 with your FTP directory and partition as needed.
  • Soft limits trigger warnings (e.g., via email or login messages), while hard limits block further writes.
  • Use cron to automate quota checks (e.g., daily):
    sudo crontab -e
    
    Add:
    0 0 * * * /usr/sbin/quotacheck -cum /home
    0 0 * * * /usr/sbin/quotaon -vug /home
    

By following these steps, you can effectively manage disk space usage on your Debian FTP server and prevent abuse.

0