How can i limit disk space usage for one user?
Solution 1:
The standard way to do it in UNIX is through the quota
command. It allows you to dynamically change how much disk space each user can use.
See the man page, or google for a tutorial.
Solution 2:
To restrict hard disk usage per user efficiently we could create a separate partition for each of the /home
directories. However then it's obviously not so easy to change the granted space or add new users.
We therefore may use fixed sized images as a container for the users /home
and mount these as loop devices (as root):
1 mkdir /media/users/
2 dd if=/dev/zero of=/media/users/john123.img bs=512K count=200
3 mkfs.ext4 /media/users/john123.img
4 mkdir /home/john123
For testing:
5 mount -o loop /media/users/john123.img /home/john123
After having done so we then create our user john123 who will now have 100 MB space available in his /home/john123
.
Subsequently the loop devices will have to be mounted prior to login, e.g. by adding this to /etc/fstab
:
6 /media/users/john123.img /home/john123 ext4 loop 0 2
Solution 3:
The route to take may be to limit the size of a user's home directory, i.e. limit /home/jake155 to a certain size. Typically a non-admin user cannot access anything beyond their home directory unless you change permissions otherwise. This thread discusses multiple ways to do that.