1.4 KiB
1.4 KiB
LFCS 5.3: User resource limits
Limiting users' processes, open files and logins with pam_limits, changing the limits of a running process, and capping a user's memory with systemd.
Before you start
The lab creates group students with members student1 and student2,
and user alice (password Lab-Pass-1, shell bash). Service lab-worker
runs a program of the same name as alice. So that le-lab check can test
ssh logins, the lab puts a key in student2's ~/.ssh/authorized_keys.
Tasks
- Limit each member of group
studentsto 50 processes. Test it withsudo -iu student1 bash -c 'ulimit -u'. - Give user
alicean open-file limit of 10000 soft and 20000 hard. Test it withsudo -iu alice bash -c 'ulimit -Sn; ulimit -Hn'. - Allow members of
studentsat most two simultaneous logins. Test it with threessh student1@localhostsessions at once. - Find the open-file limits the running
lab-workerprocess has, and write them to/root/lab-answers/4as two numbers, soft then hard. Then raise its open-file limit to 4096, soft and hard, without restarting it. - Cap all of
alice's processes together at 1 GiB of memory, and only hers.
Hints
/etc/security/limits.d/*.conf:@group,soft,hard,-, and the itemsnproc,nofileandmaxlogins. They apply at the next login.pgrep,/proc/PID/limits,prlimit --pid.systemctl set-property user-UID.slice;systemctl show -p MemoryMax.