如何限制每个用户的活动登录数?


12

如何限制每个用户的活动登录数?

我以前曾在各种服务器上看到过此消息,并且想知道如何自己设置。也许在那种情况下,这是通过限制每个用户的活动SSH登录次数来实现的?我想那是要走的路。我该如何设置?

Answers:


10

/etc/security/limits.conf,至少在Debian上。路径可能因发行版而略有不同。该文件中有一个示例,将student组的所有成员限制为4个登录(注释掉):

#<domain>      <type>   <item>          <value>
@student       -        maxlogins       4

您可以*代替小组来做,但是请确保不要打中您不想限制的用户(例如工作人员)


3
对于快速的Google员工:@student是指“学生”组的成员。要仅限制用户“学生”,请@从开头删除“ ”。
彼得-恢复莫妮卡

5

据该男子limits.conf,你可以在设置限制/etc/security/limits.conf

maxsyslogins 
maximum number of all logins on system 

因此,您可以设置(2个登录名):

* hard maxsyslogins 2

在另一个帖子中说不使用/etc/security/limits.conf。我找不到与之相关的任何东西,只是/etc/security/limits.d/*.conffile中设置的值将覆盖中的相同值/etc/security/limits.conf

pam_limits的 man pag :

缺省情况下,限制来自/etc/security/limits.conf配置文件。然后,读取/etc/security/limits.d/目录中的各个* .conf文件。文件按照“ C”区域设置的顺序依次解析。各个文件的效果与按解析顺序将所有文件串联在一起的效果相同。如果使用模块选项明确指定了配置文件,则不会解析上述目录中的文件。


maxsyslogins是总限制,而不是被问到的每个用户的限制...
Gert van den Berg

1

在现代GNU / Linux系统上,pam_limits可以限制每个用户的会话数。

为了限制每个用户的会话数,您可以在中添加条目到文件中/etc/limits.d/(例如/etc/limits.d/maxlogins.conf

# Some of the lines in this sample might conflict and overwrite each other
# The whole range is included to illustrate the possibilities
#limit users in the users group to two logins each
@users       -       maxlogins     2
#limit all users to three logins each
*            -       maxlogins     3
#limit all users except root to 20 simultaneous logins in total
*            -       maxsyslogins     20
#limit in the users group to 5 logins in total
%users       -       maxlogins     2
#limit all users with a GID >= 1000 to two logins each
1000:        -       maxlogins     2
#limit user johndoe to one login
johndoe      -       maxlogins     2

其他没有pam_limits模块的类Unix操作系统和系统将有所不同。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.