Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to limit users' disk space in Linux

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to limit the user's disk space in Linux, for this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem find a simpler and easier way.

How to limit user disk space

1. View disk space quotas for all users in the system

sudo repquota /dev/vda1

2. View a user's disk space quota

sudo edquota user_name

To change the user's disk space quota, simply change the soft and hard fields after the blocks field in the pop-up file. For example, the following figure sets the soft field value to 2097152 (i.e. 2G) and the hard field value to 3145728 (i.e. 3G). This means that the system will allow you to exceed 2G of disk space for a certain period of time (see Section 4 below for the time setting), but you have to reduce the disk space to less than 2G before the deadline; however, your disk space cannot exceed 3G. This is what soft and hard mean. It should be noted that the blocks and inodes fields do not need to be set, and the values of these two fields are automatically given by the system.

3. First set the disk space quota for a template user fanyiwei, and then assign its quota to the target user target_user_name. As long as the template quota has been set once, then this command is the most commonly used, very convenient.

sudo edquota -p fanyiwei target_user_name

4. Set warning period

We set the soft and hard limits on user disk space in Section 2. A hard cap is an upper limit that is absolutely not allowed to be exceeded, such as the 3G set above; a soft cap is a limit that allows you to exceed it for a short time, but there is a deadline, that is, an early warning period. The default warning period is 7 days, but you can change it with the following command

sudo edquota -t

After running, the following file will pop up, and then modify it. For example, the following figure sets the warning period to 3 days.

2. How to limit the amount of memory used by users

1. First enter the file using the following command

sudo vim /etc/security/limits.conf

After entering, if you want to limit the memory usage of each user to no more than 20G, add the statement in the figure below at the bottom.

* hard rss 21000000

If you want to limit the memory usage of a user test to no more than 20 gigabytes, you can add the command in the figure below.

@test hard rss 21000000

To explain, the four fields we wrote above mean: (1) plus * means that it works for all users, plus @test means that it only works for a certain user named test. (2)Hard means hard upper limit, you can also change it to soft upper limit. (3)Rss means we limit memory usage. (4)2100000 (KB) indicates that we limit the amount to about 20GB.

2. After modifying the above file and saving it, we can use the following command

sudo vim /etc/pam.d/login

Enter the file, add the following sentence at the bottom, and save.

session required /lib/security/pam_limits.so

3. Log out of the account and log in again. Use the following command to view the memory quota

ulimit -a

About Linux how to limit the user's disk space problem to share the answer here, I hope the above content can have some help for everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report