Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

bash script to count red hat linux concurrant logins

Our server run red hat Linux AS 5.4 with over 700 users connected.  We would like to limit users to 3 concurrent logins.  Red hat support has told me there is no built in method for limiting users to 3 concurrent logins.  

1.  Is Red Hat support correct, is there a way to limit user logins to 3 concurrent logins?
2.  Is there a simple way to identify users with multiple concurrent logins?

Thanks
0
epmmis
Asked:
epmmis
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
TintinCommented:
Edit /etc/security/limits.conf and set

*      hard maxlogins 3
0
 
savoneCommented:
How are the users logging in?  Is it via SSH?

You can run something like this to see how many people are logged in:

for i in `cat /etc/passwd | cut -d: -f 1`; do u=`who | grep -c $i`; echo $i has $u concurrent logins; done
0
 
omarfaridCommented:
To find out how many logins per user, run

who | awk '{ print $1 }' | uniq -c
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
savoneCommented:
@omarfarid, I like it! Very clean output!  Seems to taught two people something today and this is why I love Experts Exchange.
0
 
epmmisAuthor Commented:
TinTin - I am now looking into using /etc/security/limits.conf to limit the concurrent logons.  Any advice about implementing the limit?  Does the server need to be rebooted?

@omarfarid - thanks for the script It is easy and clean output.  

@savone - I tried your code on the command line.  The for loop did not work.  I have yet to put the code in a script.
0
 
omarfaridCommented:
Thank you all :)

Since I started participating in Experts Exchange my skills and knowledge improved a lot.
0
 
TintinCommented:
Pretty certain you don't need a reboot after changing limits.conf

Easiest way is to just try.
0
 
epmmisAuthor Commented:
TinTin - you get 400 points because your answer is spot on.
 omarfarid - you get 100 points because your script will help me identify the users which need to be controled by the limits.conf file.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now