Toggle navigation
主页
工具
归档
标签
Jumpserver
0
无
2020-09-02 17:26:12
0
0
myron
ssh limit perl脚本主要作用: 1.限制一个ssh用户的最大登录数为n,n可自定义. 2.支持白名单,如root、test登录不受限制. 如果一个ssh用户的最大登录数超过指定数字,则后登录的会把先前登录的踢掉,以此达到控制登录数的目的.该脚本需要主机支持perl,如果没有,需要yum安装. 脚本内容: cat /root/soft_shell/limit.pl #!/usr/bin/perl -w use strict; #white list my @ALLOW_USERS = qw{ test root rocdk890 }; #the maximum number of ssh login my $LOGIN_TIMES = 1; sub main { my @lines = `ps -eo user,pid,etime,cmd | grep sshd`; my $users; for my $line (@lines) { if(my ($user, $pid, $etime, $cmd) = $line =~ /^([^\s]+)\s+(\d+)\s+([^\s]+)\s+(sshd:.+)$/) { next if grep {$user eq $_} @ALLOW_USERS; my $proc = {'pid', $pid, 'etime', $etime, 'cmd', $cmd}; push @{$users->{$user}}, $proc; } } for my $key(keys(%$users)) { my @sshs = sort { my ($lb, $la) = (length($b->{'etime'}), length($a->{'etime'})); if($lb == $la) { $b->{'etime'} cmp $a->{'etime'}; } else { $lb <=> $la; } } @{$users->{$key}}; $LOGIN_TIMES = 1 if $LOGIN_TIMES < 1; for (1 .. $LOGIN_TIMES) { pop @sshs; }; for my $ssh (@sshs) { kill 9, $ssh->{'pid'}; } } } while(1) { main; sleep 3; } 加入开机启动: echo "nohup /root/soft_shell/limit.pl > /dev/null 2>&1" >> /etc/rc.local 后台运行: nohup /root/soft_shell/limit.pl > /dev/null 2>&1 __________________________________ http://jumpserver.easyvaas.com:42702/juser/user/list/ admin YizhiboIT123 ___________________________________ http = //jumpserver.easyvaas.com key = jgr8kxvina9o14ne ip = 0.0.0.0 port = 80 log = debug url = http://182.92.201.35 [db] engine = mysql host = rm-2ze93zcy31ug8407h.mysql.rds.aliyuncs.com port = 3306 user = jumpserver password = EMu#AaWdn6x database = jumpserver [mail] mail_enable = 1 email_host = smtp.exmail.qq.com email_port = 25 email_host_user = it@cloudfocus.cn email_host_password = YizhiboIT123 email_use_tls = False email_use_ssl = False _________________________________________________ http://alidown.yizhibo.tv/pc/EasyLive_mini_v3.0.0.1_Setup.rar /zebra/gw/upload/upload _________________________________________________
Shell
Asciinema终端录制
0
赞
1 人读过
新浪微博
微信
更多分享
腾讯微博
QQ空间
人人网
文档导航