网上搜出来3个文章,有2个都设置密码,我就想不通,就这么一个脚本设置密码有什么意思?现共享出来给大家 
ssh limit perl脚本主要作用: 
1.限制一个ssh用户的最大登录数为n,n可自定义. 
2.支持白名单,如root、test登录不受限制. 
 
如果一个ssh用户的最大登录数超过指定数字,则后登录的会把先前登录的踢掉,以此达到控制登录数的目的.该脚本需要主机支持perl,如果没有,需要yum安装. 
脚本内容: 
cat /root/soft_shell/limit.pl 
	
		
		
		
		
		
		
		
		
		
			
				
					
						| 
							09 | 
						
							#the maximum number of ssh login | 
					 
				
			 
		 
		
		
		
		
			
				
					
						| 
							13 | 
						
							  my @lines = `ps -eo user,pid,etime,cmd | grep sshd`; | 
					 
				
			 
		 
		
		
			
				
					
						| 
							15 | 
						
							  for my $line (@lines) { | 
					 
				
			 
		 
		
			
				
					
						| 
							16 | 
						
							    if(my ($user, $pid, $etime, $cmd) = $line =~ /^([^\s]+)\s+(\d+)\s+([^\s]+)\s+(sshd:.+)$/) { | 
					 
				
			 
		 
		
			
				
					
						| 
							17 | 
						
							      next if grep {$user eq $_} @ALLOW_USERS; | 
					 
				
			 
		 
		
			
				
					
						| 
							18 | 
						
							      my $proc = {'pid', $pid, 'etime', $etime, 'cmd', $cmd}; | 
					 
				
			 
		 
		
			
				
					
						| 
							19 | 
						
							      push @{$users->{$user}}, $proc; | 
					 
				
			 
		 
		
		
		
			
				
					
						| 
							22 | 
						
							  for my $key(keys(%$users)) { | 
					 
				
			 
		 
		
		
			
				
					
						| 
							24 | 
						
							      my ($lb, $la) = (length($b->{'etime'}), length($a->{'etime'})); | 
					 
				
			 
		 
		
		
			
				
					
						| 
							26 | 
						
							        $b->{'etime'} cmp $a->{'etime'}; | 
					 
				
			 
		 
		
		
		
		
		
			
				
					
						| 
							31 | 
						
							    $LOGIN_TIMES = 1 if $LOGIN_TIMES < 1; | 
					 
				
			 
		 
		
			
				
					
						| 
							32 | 
						
							    for (1 .. $LOGIN_TIMES) { pop @sshs; }; | 
					 
				
			 
		 
		
		
			
				
					
						| 
							34 | 
						
							      kill 9, $ssh->{'pid'}; | 
					 
				
			 
		 
		
		
		
		
		
		
		
	 
 
 
 
加入开机启动: 
echo "nohup /root/soft_shell/limit.pl > /dev/null 2>&1" >> /etc/rc.local 
 
后台运行: 
nohup /root/soft_shell/limit.pl > /dev/null 2>&1 
 
 
      (责任编辑:IT) |