- 論壇徽章:
- 0
|
#首次發(fā)布于www.linuxsir.com
# 本人整理翻譯自pam-6.html
在Linux中通過PAM的一個模塊:pam_limits 可以非常簡單的實現(xiàn)對某些用戶,或者組的系統(tǒng)資源使用限制,甚至不用重啟機器.
下面我們先看看這個模塊的說明:
模塊名稱:
pam_limits
作者:
Cristian Gafton <gafton@redhat.com>;
Elliot Lee <sopwith@redhat.com>; 貢獻了很多注釋
維護者:
Cristian Gafton - 1996/11/20
Management groups provided:
session
系統(tǒng)倚賴:
需要一個 /etc/security/limits.conf 文件 和內(nèi)核對資源限制的支持,同時也需要使用 libpwdb 庫
接收的參數(shù):
debug; conf=/path/to/file.conf
描述:
通過讀取配置文件: /etc/security/limits.conf, 能夠對用戶的session進行資源限制. 但是uid=0的用戶的資源不進行限制 .
通過以下參數(shù)可以修改這個模塊的屬性:
* debug - verbose logging to syslog(3).
* conf=/path/to/file.conf - indicate an alternative limits configuration file to the default.
* change_uid - change real uid to the user for who the limits are set up. Use this option if you have problems like login not forking a shell for user who has no processes. Be warned that something else may break when you do this.
建議使用方法:
首先應該有個一個僅root用戶能讀的文件 (默認是 /etc/security/limits.conf). 這個文件定義了限制的規(guī)則.
每行都定義了一個針對用戶或組的限制
<domain>; <type>; <item>; <value>;
<domain>; 應該是:
* 一個用戶名
* 一個組名,格式如下 @group
* 匹配模式 "*", 給默認的設置
<type>; 可以有三個值:
* hard for enforcing hard resource limits. 這些限制由超級用戶設置,內(nèi)核負責強制執(zhí)行.用戶無法改變他們對系統(tǒng)資源的最高使用限額 .
* soft for enforcing soft resource limits. These limits are ones that the user can move up or down within the permitted range by any pre-exisiting hard limits. The values specified with this token can be thought of as default values, for normal system usage.
* - for enforcing both soft and hard limits together.
<item>; 可以是如下:
* core - limits the core file size (KB)
* data - max data size (KB)
* fsize - maximum filesize (KB)
* memlock - max locked-in-memory address space (KB)
* nofile - max number of open files
* rss - max resident set size (KB)
* stack - max stack size (KB)
* cpu - max CPU time (MIN)
* nproc - max number of processes
* as - address space limit
* maxlogins - max number of logins for this user.
* priority - the priority to run user process with
這些限制是基于每個LOGIN 的,而并非全局的設置.
示例文件:
# EXAMPLE /etc/security/limits.conf file:
# =======================================
# <domain>; <type>; <item>; <value>;
* soft core 0
* hard rss 10000
@student hard nproc 20
@faculty soft nproc 20
@faculty hard nproc 50
ftp hard nproc 0
@student - maxlogins 4
然后再來看看我們系統(tǒng)中哪里使用了這個模塊.
[cat /etc/pam.d/syatem-auth]
如果你看到這行:
session required /lib/security/$ISA/pam_limits.so
那么說明你的系統(tǒng)已經(jīng)可以使用這個限制的機制了.
你所要做的僅僅是修改/etc/security/limits.conf 文件. |
|